Forum Moderators: open
I would like to have about 10 variables
<xsl:variable name="syr">System Responsible</xsl:variable>
<xsl:variable name="sur">Support Responsible</xsl:variable>
<xsl:variable name="sar">Sales Responsible</xsl:variable>
and so on.
In my xml source I have an element <activity responsible="#*$!"...>. The responsible attribute can have one of the 10 values above, i.e. "syr, sur, sar ..." and so on.
When outputting an activity, I would like to use the responsible attribute to get the variable name and print out the value of that variable, like:
<xsl:value-of select="$(@responsible)" /> (in plain words :-))
but I cannot work it out...
Thanks in advance
/Claes
You want the name of the variable in the select XPath to be dictated by the XML?
If so, I'll have to think about it. May not be able to get there from here, but we can usually find a workaround.
BTW: Are you restricted to XSLT 1 (i.e. use it in PHP)?
<xsl:choose>
<xsl:when test="@responsible='syr'">
<xsl:text>System Responsible</xsl:text>
</xsl:when>
<xsl:when test="@responsible='sur'">
<xsl:text>Support Responsible</xsl:text>
</xsl:when>
:
:
</xsl:choose>
Instead I'd like to use @responsible attribute of the activity element and use it to "fetch" the right variable to print out "System Responsible", "Support Responsible" or other.
Yes, for the moment I am stuck with XSLT 1.0
Thanks again!
/Claes
Below is a working example
XML
<?xml version="1.0" encoding="UTF-8"?>
<x>
<activity responsible="sur" />
<activity responsible="syr" />
<activity responsible="sar" />
</x>
XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/x/activity">
<div>
<xsl:call-template name="responsible">
<xsl:with-param name="r" select="@responsible"></xsl:with-param>
</xsl:call-template>
</div>
</xsl:template>
<xsl:template match="responsible" name="responsible">
<xsl:param name="r"></xsl:param>
<xsl:if test="$r='syr'">System Responsible</xsl:if>
<xsl:if test="$r='sur'">Support Responsible</xsl:if>
<xsl:if test="$r='sar'">Sales Responsible</xsl:if>
</xsl:template>
</xsl:stylesheet>
Output
<?xml version="1.0" encoding="UTF-8"?>
<div>Support Responsible</div>
<div>System Responsible</div>
<div>Sales Responsible</div>
Oohh... so simple...,
I always end up complicating things...
Thanks!
That guy's pretty good.
My experience is is that XSLT is a "non-linear language." Many of the solutions I have found come from not only thinking outside the box, but taking psychedelics, and then working on the issue.
To wit [webmasterworld.com]