Applying templates to parameters

Discussion in 'XML' started by Thomas Sommer, Oct 17, 2004.

  1. Hi,

    I think the following is not possible but maybe (hopefully) I am wrong:

    I have:

    <xsl:param name="test">
    <tag1>asdfasdf</tag1>
    <tag2>asdfasdf</tag2>
    </xsl:param>

    Is the following possible ?

    <xsl:apply-templates select="$test/tag1"/>

    Thanks

    Thomas
     
    Thomas Sommer, Oct 17, 2004
    #1
    1. Advertising

  2. Thomas Sommer

    Marrow Guest

    Hi Thomas,

    No, it is not possible in XSLT 1.0 - because the $test param would contain
    an RTF (Result Tree Fragment) and RTF's cannot be used as node-sets in XPath
    expressions.

    Many XSLT engines have an extension function (e.g. msxsl:node-set() or
    exslt:node-set() functions) that will convert an RTF to a node-set. This
    route, obviously, makes your stylesheets far less portable.

    If the content within your <xsl:param> is static/constant XML that is to be
    defaulted to if no <xsl:with-param> value overrides it then there is an
    alternative method that avoids using extension functions, e.g....

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:static="urn:my-static-stuff">
    <xsl:eek:utput method="text"/>

    <static:stuff>
    <tag1>asdfasdf</tag1>
    <tag2>asdfasdf</tag2>
    </static:stuff>

    <xsl:template match="/">
    <xsl:call-template name="test-param-defaults">
    </xsl:call-template>
    </xsl:template>

    <xsl:template name="test-param-defaults">
    <xsl:param name="test" select="document('')/*/static:stuff"/>
    <xsl:apply-templates select="$test/tag1"/>
    </xsl:template>

    <xsl:template match="tag1">
    <xsl:text>tag1 matched</xsl:text>
    </xsl:template>
    </xsl:stylesheet>


    HTH
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator


    "Thomas Sommer" <> wrote in message
    news:p...
    > Hi,
    >
    > I think the following is not possible but maybe (hopefully) I am wrong:
    >
    > I have:
    >
    > <xsl:param name="test">
    > <tag1>asdfasdf</tag1>
    > <tag2>asdfasdf</tag2>
    > </xsl:param>
    >
    > Is the following possible ?
    >
    > <xsl:apply-templates select="$test/tag1"/>
    >
    > Thanks
    >
    > Thomas
     
    Marrow, Oct 17, 2004
    #2
    1. Advertising

  3. Thanks for the info. It definitely helps.


    Thomas
     
    Thomas Sommer, Oct 17, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hardeep Rakhra
    Replies:
    12
    Views:
    619
    Eric Bohlman
    Jan 8, 2004
  2. Kimmo
    Replies:
    2
    Views:
    996
    Kimmo
    Jul 7, 2004
  3. JKop
    Replies:
    3
    Views:
    480
  4. Christoph

    Applying templates

    Christoph, Sep 26, 2006, in forum: XML
    Replies:
    3
    Views:
    423
    Joe Kesselman
    Sep 26, 2006
  5. recover
    Replies:
    2
    Views:
    814
    recover
    Jul 25, 2006
Loading...

Share This Page