在我的 XSLT 中,我有类似的东西:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/>
<xsl:template match="PhyscianTotals" name="PhyscianTotals">
<xsl:for-each select="PhysicianTotals">
<xsl:for-each-group select="Statistic" group-by="Type">
<xsl:if test="Title='PHYSICIAN DETAIL TOTAL'">
<xsl:element name="totals">
</xsl:element>
</xsl:if>
</xsl:for-each-group>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
这是有效的 XSLT 吗?具体来说,“xsl:if 在 xsl:for-each-group 内”部分。我们调用的 XSLT 编译工具之一总是报错:在样式表的这个位置不允许使用 xsl:if。如果我删除 xsl:for-each-group,它就会通过。我不确定是我的 xslt 有错误还是编译工具。
结果我们的工具只支持 XSLT 1.0。所以我想我回来只使用 1.0 标签重写 XSLT。
原始 XML 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<PhysicianTotals>
<Statistic>
<Title>PHYSICIAN TOTAL</Title>
<Type>Type 1</Type>
<Key>Cases</Key>
<Value>1</Value>
</Statistic>
<Statistic>
<Title>PHYSICIAN TOTAL</Title>
<Type>Type 1</Type>
<Key>Percentage</Key>
<Value>25.0%</Value>
</Statistic>
<Statistic>
<Title>PHYSICIAN TOTAL</Title>
<Type>Type 2</Type>
<Key>Cases</Key>
<Value>3</Value>
</Statistic>
<Statistic>
<Title>PHYSICIAN TOTAL</Title>
<Type>Type 1</Type>
<Key>Percentage</Key>
<Value>75.0%</Value>
</Statistic>
</PhysicianTotals>
输出将如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<totals>
<type>PHY_DETAIL</type>
<detailInfo>
<code>Type 1</code>
</detailInfo>
<count>
<caseValue>1</caseValue>
<percentValue>25.0%</percentValue>
</count>
</totals>
<totals>
<type>PHY_DETAIL</type>
<detailInfo>
<code>Type 2</code>
</detailInfo>
<count>
<caseValue>3</caseValue>
<percentValue>75.0%</percentValue>
</count>
</totals>