1

在我的 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>
4

2 回答 2

1

Apart from the copy/paste error in the xsl:output declaration, your code looks perfectly OK to me. It's a bit suspect - do you really have an element called PhyscianTotals with a child called PhysicianTotals - so I suspect you're not showing us the code that actually generates the error.

Another possibility is that the tool generating the error is an XSLT 1.0 processor.

于 2012-11-02T13:18:21.463 回答
0
enchttp://stackoverflow.com/editing-helpoding="UTF-8"

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

你的意思是encoding

除此之外,没有其他词法/语法错误,而且转换似乎存在许多逻辑问题,可能不会产生想要的结果——但如果没有看到源 XML 文档和期望的结果。

于 2012-11-02T01:36:24.123 回答