首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用"xsl:value-of select“截断标记

用"xsl:value-of select“截断标记
EN

Stack Overflow用户
提问于 2015-10-14 10:04:54
回答 1查看 176关注 0票数 0

当我执行下面的xsl时,我会得到一个截断的标记对,而不是完整的标记(请参阅问题的末尾)。

原始代码:

代码语言:javascript
复制
<xsl:template match="node()\@*">
<xsl:copy>
    <xsl:apply-templates select="node()\@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="CONFIG">
<xsl:choose>
    <xsl:when test=" ../ID/.='2'">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:text>STANDARD</xsl:text>
        </xsl:copy>
    </xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="NAME">
<xsl:choose>
    <xsl:when test=" ../ID/.='2'">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:text>DEVELOPMENT</xsl:text>
        </xsl:copy>
    </xsl:when>
</xsl:choose>
</xsl:template>

修改后的代码:

代码语言:javascript
复制
<xsl:template match="node()\@*">
<xsl:copy>
    <xsl:apply-templates select="node()\@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="CONFIG">
<xsl:choose>
    <xsl:when test=" ../ID/.='2'">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:text>STD</xsl:text>
        </xsl:copy>
        <xsl:attribute name="KEY">
            <xsl:value-of select='0'/>
        <xsl:attribute>
        <xsl:attribute name="NAME">
            <xsl:value-of select="'DEVELOPMENT'"/>
        <xsl:attribute>
    </xsl:when>
</xsl:choose>
</xsl:template>

因此,我的想法不是仅仅将配置设置为“标准”,我还试图设置键。我没有两次处理相同的“查询”,而是向上移动了名称的设置。

键被正确设置;但是我得到截断的<NAME>而不是

<NAME>DEVELOPMENT</NAME>

我显然不是一个XML的家伙,只是做一些维护。如有任何线索或建议,敬请见谅。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-14 10:15:19

不能在输出元素的内容之后创建属性。

<xsl:attribute>移动到<xsl:text>上方。

代码语言:javascript
复制
<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="CONFIG[../ID = '2']">
    <xsl:copy>
        <xsl:apply-templates select="@*" />
        <xsl:attribute name="KEY">0<xsl:attribute>
        <xsl:attribute name="NAME">DEVELOPMENT<xsl:attribute>
        <xsl:text>STD</xsl:text>
    </xsl:copy>
</xsl:template>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33122405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档