C
Colin Toal
Hi all,
I'm starting to learn XSLT - and have what I think is a very basic
question:
I have a stylesheet like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl
aram name="objectname"/>
<xsl:template match="/Root">
<xsl:apply-templates select="./$objectname"/>
</xsl:template>
<xsl:template match="$objectname">
<Result>
<xsl:value-of select="."/>
</Result>
</xsl:template>
</xsl:stylesheet>
and XML like this:
<?xml version="1.0" ?>
<Root>
<Value1>1</Value1>
<Value2>2</Value2>
<Value3>3</Value3>
</Root>
Now, I'd like to pass a name of a child element of Root (like Value1
or Value2) from a Java class into this stylesheet as param
'objectname'.
I can pass the parameter fine (I have tested this), but I understand
that this won't work because the XSLT interpretor cannot resolve the
value of $objectname as part of an XPath expression representing a
nodeset.
What I'd like to know is if there is some way to accomplish the same
thing ? I apologize if this question has been asked a million times by
a million newbies in the past, but I haven't found a way to do it yet
- I've even considered resorting to something 'strange' like running
my XSLT template through another XSLT template that resolves all the
'parameterized XPath expressions' into their explicit forms - but that
feels 'terribly inelegant'.
Thanks in advance - please reply directly as above.
Colin
I'm starting to learn XSLT - and have what I think is a very basic
question:
I have a stylesheet like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl
<xsl:template match="/Root">
<xsl:apply-templates select="./$objectname"/>
</xsl:template>
<xsl:template match="$objectname">
<Result>
<xsl:value-of select="."/>
</Result>
</xsl:template>
</xsl:stylesheet>
and XML like this:
<?xml version="1.0" ?>
<Root>
<Value1>1</Value1>
<Value2>2</Value2>
<Value3>3</Value3>
</Root>
Now, I'd like to pass a name of a child element of Root (like Value1
or Value2) from a Java class into this stylesheet as param
'objectname'.
I can pass the parameter fine (I have tested this), but I understand
that this won't work because the XSLT interpretor cannot resolve the
value of $objectname as part of an XPath expression representing a
nodeset.
What I'd like to know is if there is some way to accomplish the same
thing ? I apologize if this question has been asked a million times by
a million newbies in the past, but I haven't found a way to do it yet
- I've even considered resorting to something 'strange' like running
my XSLT template through another XSLT template that resolves all the
'parameterized XPath expressions' into their explicit forms - but that
feels 'terribly inelegant'.
Thanks in advance - please reply directly as above.
Colin