0

我正在使用 XslCompiledTransform.Load 并且每次收到错误消息时:

 'version' cannot be a child  of the 'Transformation' element

这是样式表:

<Transformation><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts" 
xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"><xsl:output 
method="xml" /><xsl:template match="node() | @*"><xsl:copy><xsl:apply-templates 
select="@* | node()" /></xsl:copy></xsl:template><xsl:template match="testlist"><xsl:copy>
<xsl:apply-templates select="test"><xsl:sort select="requestor/code" /></xsl:apply-   
templates></xsl:copy></xsl:template></xsl:stylesheet></Transformation>

如果我删除版本,我会收到错误:缺少强制属性“版本” 是否因为我在标签“转换”中使用样式表而收到错误?

4

1 回答 1

1

您的问题的答案是“是”。你确实得到了错误,因为你只有xsl:stylesheet元素内的Transformation元素

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

xsl:stylesheet需要是根元素,所以Transformation需要删除。

话虽如此,也许你打算这样做......

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
  xmlns:user="urn:my-scripts" 
  xmlns:exsl="http://exslt.org/common" 
  extension-element-prefixes="exsl">
   <xsl:output method="xml"/>

   <xsl:template match="/">
      <Transformation>
         <xsl:apply-templates select="@* | node()"/>
      </Transformation>
   </xsl:template>

   <xsl:template match="node() | @*">
      <xsl:copy>
         <xsl:apply-templates select="@* | node()"/>
      </xsl:copy>
   </xsl:template>

   <xsl:template match="testlist">
      <xsl:copy>
         <xsl:apply-templates select="test">
            <xsl:sort select="requestor/code"/>
         </xsl:apply-templates>
      </xsl:copy>
   </xsl:template>
 </xsl:stylesheet>
于 2014-09-11T18:44:36.623 回答