2015-03-13 24 views
0
<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:str = "http://exslt.org/string" extension-element-prefixes="str"> 
<xsl:template name="padding"> 
    <xsl:param name="padChar" select="' '"/> 
    <xsl:param name="padVar"/> 
    <xsl:param name="length"/> 
    <xsl:choose> 
    <xsl:when test="$length > string-length($padVar) "> 

     <xsl:call-template name="padding"> 
      <xsl:with-param name="padChar" select="$padChar"/> 
      <xsl:with-param name="padVar" select="concat($padVar,$padChar)"/> 
      <xsl:with-param name="length" select="$length"/> 
     </xsl:call-template> 

    </xsl:when> 
    <xsl:otherwise> 
     <xsl:value-of select="substring($padVar,1,$length)"/> 
    </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 

<xsl:param name="member" /> 
<xsl:template match = "/"> 
    <xsl:for-each select="record/transaction"> 
     <transaction> 
     <!--  <xsl:template match="member"> 
        <xsl:call-template name="padding"/> 
       </xsl:template>--> 
       <xsl:template match = "date"> 
        <xsl:call-template name="padding"> 
         <xsl:with-param name = "padVar">20</with-param> 
         <xsl:with-param name = "length">50</with-param> 
       <!-- <xsl:value-of select = "str:align(date,str:padding(100))"/> --> 
        </xsl:call-template> 
       </xsl:template> 
       <type> 
        <xsl:value-of select = "type"/> 
       </type> 
       <amount> 
        <xsl:value-of select = "amount"/> 
       </amount> 
       <remark> 
        <xsl:value-of select = "remark"/> 
       </remark> 
      </transaction> 
     </xsl:for-each> 
</xsl:template> 
</xsl:stylesheet> 

我无法检测到上述代码中的错误。任何人都可以帮忙吗?错误在传递参数的XSLT代码?

我认为错误是在我传递参数名称的时候,当我调用模板时。另外,有人可以分享一个链接,我可以在哪里了解XSLT参数?

+0

什么是exactely症状?提供一个示例输入XML。 – potame 2015-03-13 08:12:43

+0

错误可能来自''。它必须位于样式表中的或最上面的位置(在所有的标签之前)。 – potame 2015-03-13 08:14:47

+3

这个错误几乎肯定是因为你在另一个模板匹配('')中嵌入了'“。这是不允许的,因为模板必须是样式表元素的直接子对象。如果你想知道如何改变你的XSLT来使它工作,我们真的需要看到你的输入XML和你的期望输出,并且让你准确地解释你想要达到的目标。谢谢! – 2015-03-13 09:02:41

回答

3

与撒克逊运行这样的:首先尝试生产

Error on line 33 column 61 of test.xsl: 
    SXXP0003: Error reported by XML parser: The element type "xsl:with-param" must be terminated by the matching end-tag "</xsl:with-param>". 

修复此产生:

Error at xsl:template on line 31 column 46 of test.xsl: 
    XTSE0010: An transaction element must not contain an xsl:template element 
Error at xsl:template on line 31 column 46 of test.xsl: 
    XTSE0010: Element xsl:template must be top-level (a child of xsl:stylesheet, xsl:transform, or xsl:package) 

这些都是很基本的错误,我希望你理解他们。如果您没有看到用这些术语解释问题的错误消息,那么您可能需要考虑使用不同的开发环境。例如,有些人试图通过直接在浏览器中运行XSLT代码来开发XSLT代码:当您发现错误时,这会给您带来绝望的无法诊断。