如何解决XSLT中“在样式表编译期间报告错误"的问题? [英] How to fix 'Errors were reported during stylesheet compilation' in XSLT?

查看:85
本文介绍了如何解决XSLT中“在样式表编译期间报告错误"的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 https://xslttest.appspot.com/.它返回此错误:

I have this SaxonApiException when I run my XSLT code on https://xslttest.appspot.com/. It return this error :

net.sf.saxon.s9api.SaxonApiException:样式表编译期间报告了错误

net.sf.saxon.s9api.SaxonApiException: Errors were reported during stylesheet compilation

我尝试了另一台在线测试仪 https://www.freeformatter.com/xsl-transformer .html ,但出现相同的错误. 我试图拆分我的XSLT代码.第一部分是在工资中提取ZipCode的过程,第二部分是在地址中提取ZipCode的过程. 两者都分开时有效,所以我认为我在选择"元素上犯了一个错误,但找不到它.

I tried on another online tester https://www.freeformatter.com/xsl-transformer.html but I got the same error. I tried to split my XSLT code. First part with the process of extract ZipCode in Wages and second part with the process of extract ZipCode in Addresses. Both works when they're separated so I think I made a mistake in the 'choose' element but cannot find it.

这是我的XSLT代码...

Here is my XSLT code...

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/EmployeeUDM_Response/Return/Employee">
  <xsl:for-each select="./Wages/Wage">
    <xsl:choose>
      <xsl:when test="DissimelarZipCode != ''">
        <xsl:value-of select="DissimelarZipCode" />
      </xsl:when>
      <otherwise>
        <xsl:for-each select="./Addresses/Address" />
          <!-- year -->
          <xsl:sort select="substring(StartDate, 1, 4)" order="descending" data-type="number"/>
          <!-- month -->
          <xsl:sort select="substring(StartDate, 6, 2)" order="descending" data-type="number"/>
          <!-- day -->
          <xsl:sort select="substring(StartDate, 9, 2)" order="descending" data-type="number"/>
          <xsl:if test="position() = 1">
            <xsl:value-of select="./ZipCode" />
          </xsl:if>
      </otherwise>
    </xsl:choose>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

...以及我的XML文件

...and my XML file

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl"?>
<EmployeeUDM_Response xmlns:ns0="http://ESB/Schemas/v2/EmployeeUDM">
    <Header Type="Employee" Source="Biztalk ESB" />
    <Return>
        <Employee>
            <Wages>
                <Wage>                  
                    <StartDate>2019-04-22T00:00:00.0000000+02:00</StartDate>
                    <EndDate>2019-05-01T00:00:00.0000000+02:00</EndDate>
                    <DissimelarZipCode>5430 NU</DissimelarZipCode>
                </Wage>
            </Wages>
                        <Addresses>
                <Address>
                    <StartDate>2014-01-01T00:00:00.0000000+02:00</StartDate>
                    <EndDate></EndDate>
                    <ZipCode>6099 EB</ZipCode>
                </Address>
                <Address>
                    <StartDate>2015-01-01T00:00:00.0000000+02:00</StartDate>
                    <EndDate></EndDate>
                    <ZipCode>5487 YR</ZipCode>
                </Address>
            </Addresses>
        </Employee>
    </Return>
</EmployeeUDM_Response>

我希望在Wage中输出ZipCode(在这种情况下为5430 NU),或者如果在Wage中ZipCode为空,则在地址中的ZipCode具有最新的StartDate(在这种情况下为5487 YR)

I expected the output of the ZipCode in Wage (5430 NU in this case) or, if ZipCode in Wage is empty, the ZipCode in Address with the latest StartDate (5487 YR in this case)

推荐答案

1..应该是<xsl:otherwise>而不是<otherwise>

2. <xsl:sort>应该在<xsl:for-each>中.(您已在同一行中结束了循环)

2. <xsl:sort> should be in <xsl:for-each> .(You have ended the loop in same line)

3..要遍历Address,您将需要xpath ../../Addresses/Address.因为当时正在处理<Wage>. (../将使您上一级父节点.)

3. To loop over Address, you will need xpath ../../Addresses/Address. Because at that time <Wage> is being processed. ( ../ will bring you up one level to parent node.)

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:template match="/EmployeeUDM_Response/Return/Employee">
        <xsl:for-each select="Wages/Wage">
            <xsl:choose>
                <xsl:when test="DissimelarZipCode != ''">
                    <xsl:value-of select="DissimelarZipCode" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:for-each select="../../Addresses/Address">
                        <!-- year -->
                        <xsl:sort select="substring(StartDate, 1, 4)" order="descending"
                            data-type="number" />
                        <!-- month -->
                        <xsl:sort select="substring(StartDate, 6, 2)" order="descending"
                            data-type="number" />
                        <!-- day -->
                        <xsl:sort select="substring(StartDate, 9, 2)" order="descending"
                            data-type="number" />
                        <xsl:if test="position() = 1">
                            <xsl:value-of select="ZipCode" />
                        </xsl:if>
                    </xsl:for-each>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

https://xsltfiddle.liberty-development.net/pPzifpP

这篇关于如何解决XSLT中“在样式表编译期间报告错误"的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆