XSLT Question

G

gwoodhouse

Hello,

I'm trying to transform XML that can come in server forms,

The XML i get is along these lines (This is example simplified code)

<composer>
<composer_if>jim</composer_if>
<composer_epithet>mr</composer_epithet>
</composer>

or

<artist>
<artist_if>bob</artist_if>
<artist_epithet>sir</artist_epithet>
</artist>

(or any number of different permutations of this)

I'm trying to use this code to display it in the form Mr, Jim or Sir,
Bob:

<xsl:template match="advertiser|artist|box_office|company|composer|
distributor|editor|for_benefit_of|lessee|owner|premises_owner|
producer_director|scenery_designer|signatory">
<xsl:choose>
<xsl:when test="main[@display = 'yes']">
<xsl:apply-templates select="main"/>
</xsl:when>
<xsl:eek:therwise>
<xsl:variable name="if">
<xsl:value-of select="name()"/><xsl:text>_if</xsl:text>
</xsl:variable>
<xsl:variable name="epithet">
<xsl:value-of select="name()"/><xsl:text>_epithet</xsl:text>
</xsl:variable>
<xsl:apply-templates select="$if"/>, <xsl:apply-templates
select="$epithet"/>
</xsl:eek:therwise>
</xsl:choose>
<xsl:apply-templates/>
</xsl:template>

But the XSLT proccessor doesn't like using variable's in its "select"
attribute.

Does anyone know a way around this without changing the XML being
passed in?

Thanks

Graeme
 
M

Martin Honnen

<xsl:variable name="if">
<xsl:value-of select="name()"/><xsl:text>_if</xsl:text>
</xsl:variable>

That would better be coded as
<xsl:apply-templates select="$if"/>, <xsl:apply-templates
select="$epithet"/>

this work.

What you probably want is simply

<xsl:apply-templates select="*[name() = $if]"/>
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top