This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
conditional XSL to XSL
- To: xsl-list at mulberrytech dot com
- Subject: conditional XSL to XSL
- From: Jeff Lansing <jeff at dtai dot com>
- Date: Thu, 06 Apr 2000 12:29:25 -0700
- Reply-To: xsl-list at mulberrytech dot com
Here is some minimal test input:
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<el attr="x"/>
<el attr="y"/>
</doc>
Here is my stylesheet:
<x:stylesheet xmlns:x="http://www.w3.org/1999/XSL/Transform"
xmlns:xsl="anything" version="1.0">
<x:output method="xml" indent="yes"/>
<x:namespace-alias stylesheet-prefix="xsl" result-prefix="x"/>
<x:template match="/">
<xsl:stylesheet version="1.0">
<x:apply-templates/>
</xsl:stylesheet>
</x:template>
<x:template match="el">
<x:if test="@attr = 'x'">
<xsl:template match="tr[@class='title']">
<xsl:value-of select="foo"/>
<!--whole bunch of other complicated stuff-->
</xsl:template>
</x:if>
<x:if test="not(@attr = 'x')">
<xsl:template match="tr[@class='title' and position() > 1]">
<xsl:value-of select="foo"/>
<!--whole bunch of other complicated stuff-->
</xsl:template>
</x:if>
</x:template>
</x:stylesheet>
Here is my problem (very real, even if the above seems contrived):
I would like to eliminate duplication in the above stylesheet by
conditionally
setting a variable, call it 'match-value', and using it in the
"xsl:template" thingy,
which I think would work like this:
<xsl:template match="{$match-value}">
<xsl:value-of select="foo"/>
<!--whole bunch of other complicated stuff-->
</xsl:template>
So if that's right I would need to set the variable something like this:
<x:variable name="match-value">
<x:if test="@attr = 'x'">
<x:value-of select="'value1'"/>
</x:if>
<x:if test="not(@attr = 'x')">
<x:value-of select="'value2'"/>
</x:if>
</x:variable>
But I'm just not being able to get the right stuff into 'value1' (or
'value2');
I've tried things like:
'tr[@class="title"]'
and
'tr[@class='title']'
but I'm not getting any of saxon/xt/xalan to accept any thing like
these.
Jeff
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list