[xsl] Alternative to variable in template match

Subject: [xsl] Alternative to variable in template match
From: Rick Anderson <rianders@xxxxxxxxxxxxxxx>
Date: Thu, 17 Jan 2002 15:54:28 -0500 (EST)
I wrote a small xsl to copy the nodes below a specified XPATH expression
into new files. I wanted to eventually pass the XPATH in via a command
line.

Since a variable can't be used in 'template match="$path"' there must be
another efficient way to do this. Currently, my work around doesn't
compare the XPATH expression to the node successfully. Any hints?


xsl:
----
<xsl:stylesheet version="1.1"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml"/>

<xsl:variable name="dir" select="'out'" />
<xsl:variable name="prefix" select="'name'" />
<xsl:variable name="suffix" select="'xml'" />
<xsl:variable name="xpath"  select="a"/>


<xsl:template match="*">

<xsl:if test="$xpath" >
        <xsl:variable name="filename" select="concat($dir,'/',$prefix,
position(),'.',$suffix)"/>

        <xsl:document href="{$filename}">
        <doc>
                <xsl:copy-of select="node()"/>
        </doc>
        </xsl:document>

</xsl:if>

</xsl:template>
</xsl:stylesheet>


----

xml:
----
<doc>
<a>
<b>
<c>This is 1</c>
</b>
</a>

<a>
<b>
<c>This is 2</c>
</b>
</a>

<a>
<b>
<c>This is 3</c>
</b>
</a>

</doc>


----



Thanks,
--Rick Anderson


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread