Xslt 在阵列中存储节点

Xslt 在阵列中存储节点,xslt,xslt-2.0,Xslt,Xslt 2.0,是否可以将所有内容节点存储为一个数组并传递给另一个模板?我试过了,但没能成功。我的选择表达式正在选择正确的节点 <xsl:variable name="array" select="/data/contents/content[ ..... ] /> <xsl:value-of select="$array/.../... " /> <xsl:variable name="bannerList" select="data/contents[$

是否可以将所有内容节点存储为一个数组并传递给另一个模板?我试过了,但没能成功。我的选择表达式正在选择正确的节点

  <xsl:variable name="array" select="/data/contents/content[ .....  ] />
   <xsl:value-of select="$array/.../... " />


    <xsl:variable name="bannerList" select="data/contents[$dayOfWeekIndex]/content[position() &lt;= 5]" />

    <xsl:apply-templates select="$bannerList" mode="article">
        <xsl:with-param name="numberOfBanners" select="count($bannerList)" />
    </xsl:apply-templates>

是的,很容易接近,看看:

XML:

<body>
  <RIAssetType><text>Product</text></RIAssetType>
  <RIAssetType><text>Service</text></RIAssetType>
  <RIAssetType><text>Company/Business Unit</text></RIAssetType>
  <RIAssetType><text>Technology</text></RIAssetType>
  <RIAssetType><text>Intellectual Property/Data Only</text></RIAssetType>
</body>
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="body">
    <copyBody>
    <xsl:call-template name="childCopy">
      <xsl:with-param name="bodyChild" select="self::body/child::*"/>
    </xsl:call-template>
    </copyBody>
  </xsl:template>

  <xsl:template name="childCopy">
    <xsl:param name="bodyChild"/>
    <xsl:for-each select="$bodyChild/self::*">
      <xsl:copy>
        <xsl:copy-of select="."/>
      </xsl:copy>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
<copyBody>
  <RIAssetType>
    <RIAssetType>
      <text>Product</text>
    </RIAssetType>
  </RIAssetType>
  <RIAssetType>
    <RIAssetType>
      <text>Service</text>
    </RIAssetType>
  </RIAssetType>
  <RIAssetType>
    <RIAssetType>
      <text>Company/Business Unit</text>
    </RIAssetType>
  </RIAssetType>
  <RIAssetType>
    <RIAssetType>
      <text>Technology</text>
    </RIAssetType>
  </RIAssetType>
  <RIAssetType>
    <RIAssetType>
      <text>Intellectual Property/Data Only</text>
    </RIAssetType>
  </RIAssetType>
</copyBody>

产品
服务
公司/业务单位
技术
仅限知识产权/数据
XSLT:

<body>
  <RIAssetType><text>Product</text></RIAssetType>
  <RIAssetType><text>Service</text></RIAssetType>
  <RIAssetType><text>Company/Business Unit</text></RIAssetType>
  <RIAssetType><text>Technology</text></RIAssetType>
  <RIAssetType><text>Intellectual Property/Data Only</text></RIAssetType>
</body>
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="body">
    <copyBody>
    <xsl:call-template name="childCopy">
      <xsl:with-param name="bodyChild" select="self::body/child::*"/>
    </xsl:call-template>
    </copyBody>
  </xsl:template>

  <xsl:template name="childCopy">
    <xsl:param name="bodyChild"/>
    <xsl:for-each select="$bodyChild/self::*">
      <xsl:copy>
        <xsl:copy-of select="."/>
      </xsl:copy>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
<copyBody>
  <RIAssetType>
    <RIAssetType>
      <text>Product</text>
    </RIAssetType>
  </RIAssetType>
  <RIAssetType>
    <RIAssetType>
      <text>Service</text>
    </RIAssetType>
  </RIAssetType>
  <RIAssetType>
    <RIAssetType>
      <text>Company/Business Unit</text>
    </RIAssetType>
  </RIAssetType>
  <RIAssetType>
    <RIAssetType>
      <text>Technology</text>
    </RIAssetType>
  </RIAssetType>
  <RIAssetType>
    <RIAssetType>
      <text>Intellectual Property/Data Only</text>
    </RIAssetType>
  </RIAssetType>
</copyBody>

输出:

<body>
  <RIAssetType><text>Product</text></RIAssetType>
  <RIAssetType><text>Service</text></RIAssetType>
  <RIAssetType><text>Company/Business Unit</text></RIAssetType>
  <RIAssetType><text>Technology</text></RIAssetType>
  <RIAssetType><text>Intellectual Property/Data Only</text></RIAssetType>
</body>
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="body">
    <copyBody>
    <xsl:call-template name="childCopy">
      <xsl:with-param name="bodyChild" select="self::body/child::*"/>
    </xsl:call-template>
    </copyBody>
  </xsl:template>

  <xsl:template name="childCopy">
    <xsl:param name="bodyChild"/>
    <xsl:for-each select="$bodyChild/self::*">
      <xsl:copy>
        <xsl:copy-of select="."/>
      </xsl:copy>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
<copyBody>
  <RIAssetType>
    <RIAssetType>
      <text>Product</text>
    </RIAssetType>
  </RIAssetType>
  <RIAssetType>
    <RIAssetType>
      <text>Service</text>
    </RIAssetType>
  </RIAssetType>
  <RIAssetType>
    <RIAssetType>
      <text>Company/Business Unit</text>
    </RIAssetType>
  </RIAssetType>
  <RIAssetType>
    <RIAssetType>
      <text>Technology</text>
    </RIAssetType>
  </RIAssetType>
  <RIAssetType>
    <RIAssetType>
      <text>Intellectual Property/Data Only</text>
    </RIAssetType>
  </RIAssetType>
</copyBody>

产品
服务
公司/业务单位
技术
仅限知识产权/数据

您似乎在XPATH的某个地方找到了struct,请再次检查。

您是否可以为我们提供一个到目前为止的示例?是的,您可以将节点集作为参数传递,就像任何其他变量一样:
。您的XSLT在哪里?它没有像您期望的那样工作?我得到了计数($bannerList)=1。但是,当我尝试访问另一个模板中的任何内容时,选择=“$bannerList/../@somthing”会得到一个空结果。
@somthing
内容
元素的属性吗?如果是这样,它应该是
$bannerList/@somthing
,而不是
$bannerList/./@somthing
。正如我已经两次指出的那样,如果不不断地向您询问信息,您就无法提供必要的信息(这次是源XML)来回答您的问题。