Subject: conditional XSL to XSL From: Jeff Lansing <jeff@xxxxxxxx> Date: Thu, 06 Apr 2000 12:29:25 -0700 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: Attribute Names of the longest , Moazzam Ahmed | Thread | RE: conditional XSL to XSL, Kay Michael |
RE: Printing XML reports, Robert C. Lyons | Date | Re: XHTML to HTML 4, Mike Brown |
Month |