当我执行下面的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>因此,我的想法不是仅仅将配置设置为“标准”,我还试图设置键。我没有两次处理相同的“查询”,而是向上移动了名称的设置。
键被正确设置;但是我得到截断的<NAME>而不是
<NAME>DEVELOPMENT</NAME>
我显然不是一个XML的家伙,只是做一些维护。如有任何线索或建议,敬请见谅。
发布于 2015-10-14 10:15:19
不能在输出元素的内容之后创建属性。
将<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>https://stackoverflow.com/questions/33122405
复制相似问题