遍历XML中的每个节点

时间:2011-01-04 22:36:47

标签: xml xslt xslt-2.0

您好 我试图遍历xml中的每个节点,无论是元素节点,文本节点还是注释。在下面的XSL中就是第一个声明 打印完整的xml。如何复制$ nodes中的第一个节点并再次调用模板进程节点删除第一个节点?

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

<xsl:template match="/">
<xsl:call-template name="process-nodes">
<xsl:with-param name="nodes" select="//node()" as="node()*"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="process-nodes">
<xsl:param name="nodes" as="node()*" />
<xsl:copy-of select="$nodes[1]"/>
<xsl:if test="$nodes">
    <xsl:call-template name="process-nodes">
      <xsl:with-param name="nodes"
        select="remove($nodes, 1)" />
    </xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

注意:我正在寻找在这种实现中修复问题,而不是将模板匹配更改为<xsl:template match="@* | node()">,因为我需要进行一些需要这种方法的处理。

感谢。

4 个答案:

答案 0 :(得分:2)

目前还不是很清楚,你想要完成什么,但身份转换会处理每个节点(所有类型)和每个属性。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

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

</xsl:stylesheet>

您可以通过删除表达式的@*部分来排除属性。

答案 1 :(得分:1)

这应该在递归调用中执行:

<xsl:with-param name="nodes" select="$nodes[position()!=1]" />

答案 2 :(得分:1)

来自OP的评论

  

当我处理任何文本节点时,我需要   前面文本节点的总和。   试图找到我如何实现它   没有冗余使用该功能   前述文本长度

以下是由FXSL实现的函数式编程和高阶函数(HOF):

这是一个完整的代码示例。此转换仅将XML文档的文本节点连接到给定的总长度限制:

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:foldl-func="foldl-func"
xmlns:f="http://fxsl.sf.net/"
exclude-result-prefixes="f foldl-func"
>

   <xsl:import href="../f/func-foldl.xsl"/>

    <xsl:output method="text"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">
      <xsl:variable name="vinitParam" select="100,0,''"/>

      <xsl:value-of select="f:foldl(f:limitedConcat(), $vinitParam, //text() )"/>
    </xsl:template>

 <xsl:function name="f:limitedConcat">
  <xsl:param name="pAccumResults"/>
  <xsl:param name="pcurrentNode" as="text()"/>

  <xsl:variable name="vLengthLimit" select="$pAccumResults[1]"/>
  <xsl:variable name="vAccumLength" select="$pAccumResults[2]"/>

  <xsl:sequence select=
   "for $vNewLength in $vAccumLength+string-length($pcurrentNode),
        $vInLimit in ($vNewLength le $vLengthLimit)
     return
       ($vLengthLimit,
         (if($vInLimit)
          then $vNewLength
          else $vAccumLength) ,

        if($vInLimit)
          then concat($pAccumResults[3], $pcurrentNode)
          else $pAccumResults[3]
        )
   "/>
 </xsl:function>

 <xsl:function name="f:limitedConcat" as="element()">
  <f:limitedConcat/>
 </xsl:function>

 <xsl:template match="f:limitedConcat" mode="f:FXSL">
  <xsl:param name="arg1"/>
  <xsl:param name="arg2"/>

  <xsl:sequence select="f:limitedConcat($arg1,$arg2)"/>
 </xsl:template>
 </xsl:stylesheet>

应用于此XML文档

<booklist>
   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

   <book>
      <title>Angela's Ashes</title>
      <author>Frank McCourt</author>
      <publisher>HarperCollins</publisher>
      <isbn>0 00 649840 X</isbn>
      <price>6.99</price>
      <sales>235</sales>
   </book>
   <book>
      <title>Sword of Honour</title>
      <author>Evelyn Waugh</author>
      <publisher>Penguin Books</publisher>
      <isbn>0 14 018967 X</isbn>
      <price>12.99</price>
      <sales>12</sales>
   </book>

</booklist>

产生了想要的正确结果

100 100 Angela's AshesFrank McCourtHarperCollins0 00 649840 X6.99235Sword of HonourEvelyn WaughPenguin Books

<强>解释

这类似于:

f:foldl(f:add(), 0, 1 to 10)

上面的表达式计算从1到10的数字之和:

  • 函数f:add()作为第一个参数传递给f:foldl()

  • 第二个参数是初始累计值 - 0.

  • 第三个参数是要处理的项目序列。

foldl函数获取当前累计值和序列的当前头部(第三个参数的头部)并对它们应用f:add()函数。结果成为新的累积值,foldl()以相同的第一个参数,新累积值和序列尾部递归调用自身。

在上面的解决方案中,累积值是一个由文本长度限制,累积长度和累积字符串连接组成的三元组。

我们使用f:add()而不是f:limitedConcat(),它会添加字符串长度,如果总值不超过指定的总文本限制,还会连接当前文本节点的值。

答案 3 :(得分:0)

你的问题中隐含着矛盾。你说:

  

在第一个语句中使用下面的XSL打印完整的xml。

这意味着您不满意处理第一个节点会复制整个XML。

然后你说:

  

如何复制$ nodes中的第一个节点

但$ nodes中的第一个节点是树的根,复制它将复制整个XML。

所以问题是:你想要产生什么输出?你能描述一下你想要进行的转型吗?因为我们无法从错误的代码开始回答问题。