Applying templates to parameters

T

Thomas Sommer

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
 
M

Marrow

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top