XSL:在XSL中的IF:for-each-group

时间:2012-11-02 00:24:41

标签: xslt

在我的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 if the 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>

2 个答案:

答案 0 :(得分:1)

除了xsl:output声明中的复制/粘贴错误之外,您的代码看起来完全没问题。这有点可疑 - 你真的有一个名为PhyscianTotals的元素,其中有一个名为PhysicianTotals的孩子 - 所以我怀疑你没有向我们展示实际产生错误的代码。

另一种可能性是生成错误的工具是XSLT 1.0处理器。

答案 1 :(得分:0)

enchttp://stackoverflow.com/editing-helpoding="UTF-8"

这是语法上/词汇上的非法名称:enchttp://stackoverflow.com/editing-helpoding

您的意思是encoding吗?

除此之外没有其他词汇/语法错误,似乎转换有许多逻辑问题,可能不会产生想要的结果 - 但我不能100在没有看到源XML文档和期望结果的情况下确定。

相关问题