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

时间:2015-10-14 10:04:54

标签: xslt

当我执行以下xsl时,我得到一个截断的标记对而不是完整的标记(请参阅问题的最后部分)。

原始代码:

<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>

修改后的代码:

<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>

所以这个想法不仅仅是将CONFIG设置为&#34; STANDARD&#34;,我还试图设置KEY。 而不是处理相同的&#34;查询&#34;两次,我移动了NAME的设置。

KEY设置正确;但是我被截断了     <NAME> 而不是     <NAME>DEVELOPMENT</NAME>

我显然不是一个XML人,只是做一些维护。任何线索或建议都表示赞赏。

1 个答案:

答案 0 :(得分:0)

在输出元素内容后,您无法创建属性。

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

<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>