Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Janusz Stabik 37 posts 59 karma points
    Mar 30, 2011 @ 13:02
    Janusz Stabik
    0

    Create an XSLT nodeset to pass to template

    I have a template for a given doc type that i use all over the place and include into a number of xslt macros.  Now I want to reuse the same template with some content xml that has a different schema but has nodes (properties) that I can "map" to similar fields in the given template.  Is it possible to create a node set in my xslt file, assign it to a variable and pass that to the tempate as a param? 

    Hope that all makes sense.

    I could do it in an extension but it seems a bit overkill to me.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 30, 2011 @ 14:42
    Jan Skovgaard
    0

    Hi Janusz

    This sound like something that should be possible.

    Could you perhaps provide some snippets of the code you already have and the stuff that needs to be transformed?

    /Jan

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 30, 2011 @ 21:18
    Chriztian Steinmeier
    2

    Hi Janusz,

    You can build a variable containing XML and use the node-set() function to be able to perform XPath querying or applying templates etc.:

    <xsl:variable name="node-mapper">
        <nodes>
            <node id="1">
                <someValue>text</someValue>
                <someOtherValue attr="possible" />
            </node>
            <node id="2">
                <someValue>text</someValue>
                <someOtherValue attr="possible" />
            </node>
        </nodes>
    </xsl:variable>
    <xsl:variable name="nodes" select="msxml:node-set($node-mapper)/nodes" />
    
    <xsl:call-template name="handler">
        <xsl:with-param name="nodes" select="$nodes" />
    </xsl:call-template>
    
    <xsl:template name="handler">
        <xsl:param name="nodes" />
    
        <xsl:value-of select="$nodes/node[@id = 1]/someValue" />
        <!-- etc -->
    
    </xsl:template>
    
    What does your existing template look like? Is it a match template?

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft