我有以下XSLT,我需要将节点值从列表中拉出。
<ServiceDetails>
<xsl:for-each select="$TagList">
<xsl:choose>
<xsl:when test="contains(@ItemName, 'Test1')">
<Qty>
<xsl:value-of select="Value" />
</Qty>
<ReasonCode>
<__name>Value1</__name>
</ReasonCode>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="$TagList">
<xsl:choose>
<xsl:when test="contains(@ItemName, 'Test2')">
<Qty>
<xsl:value-of select="Value" />
</Qty>
<ReasonCode>
<__name>Value2</__name>
</ReasonCode>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</ServiceDetails>
我需要从<__name>
中提取值和<xsl:when>
元素内的属性。 (在此示例中:Test1,Test2)
我希望输出看起来像这样:
Test1 Value1
Test2 Value2
我已经可以使用下面的代码输出单个节点,但是格式化最终会在输出文本文件中出现多余的空格和缩进。
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:template match="/ServiceDetails">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="ReasonCode">
<xsl:value-of select="__name/text()"/>
</xsl:template>
</xsl:transform>
答案 0 :(得分:0)
首先,我在样式表中看不到任何试图输出第一列(Test1
,Test2
)的东西。
第二,输出中多余的空格的原因是内置模板规则将所有(空白)文本节点从输入复制到输出。您可以使用
<xsl:template match="text()/>