0

Is it possible to store all content nodes as an array and pass to another template? I Have tried but cannot get it tho work. My select expression is selecting the correct nodes.

  <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>

I would like to use call-template instead and send the bannerList as a parameter.

4
  • And might you be so kind as to provide us with an example of what you have so far? Commented Apr 17, 2013 at 10:49
  • Yes, you can pass a nodeset as a parameter, just like any other variable: <xsl:with-param name="list" select="$bannerList" />. Where is your XSLT where that isn't working as you expect? Commented Apr 17, 2013 at 11:07
  • I got the count($bannerList) = 1 as I expected. But when i try to access anything inside another template select="$bannerList/.../@somthing" I get an empty result. Commented Apr 17, 2013 at 11:10
  • Is @somthing an attribute of content elements? If so, it should be $bannerList/@somthing, not $bannerList/../@somthing. As I've already pointed out twice, you're failing to provide the necessary information (this time the source XML) to answer your question without continually asking you for information. Commented Apr 17, 2013 at 11:39

1 Answer 1

1

Yes, it is easily approachable, have a look:

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>

XSLT:

<?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>

OUTPUT:

<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>

It seems you got struct in XPATH somewhere, please check again.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.