XSLT Question

Discussion in 'XML' started by gwoodhouse@gmail.com, Jul 17, 2009.

  1. Guest

    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
     
    , Jul 17, 2009
    #1
    1. Advertising

  2. wrote:

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


    That would better be coded as
    <xsl:variable name="if" select="concat(name(), '_if')"/>
    but that will not make

    > <xsl:apply-templates select="$if"/>, <xsl:apply-templates
    > select="$epithet"/>


    this work.

    What you probably want is simply

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

    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Jul 17, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    768
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,749
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    654
    Laurens
    Jan 26, 2004
  4. Replies:
    2
    Views:
    739
    Henry S. Thompson
    Oct 19, 2005
  5. Replies:
    18
    Views:
    2,812
    Joseph Kesselman
    Oct 4, 2006
Loading...

Share This Page