XSL variable indirection

Discussion in 'XML' started by sucheta.phatak@gmail.com, Sep 20, 2005.

  1. Guest

    Hello,

    I am trying to use XSLT. Here is the problem that I am facing.

    My XML file:

    <Book level="1" name="Mapplicationtoc1">
    ....... Some more tags
    </Book>

    My XSL file
    1) a.xsl

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:abc="http://www.abc.com/">
    <xsl:include href="../../shared/myxsl.xsl" />
    <xsl:template match="abc:Book">
    //Book
    <xsl:variable name="tempMsg">
    <xsl:value-of select="@name"/>
    </xsl:variable>

    <xsl:value-of select= "*[$tempMsg]"/>

    </xsl:template>
    </xsl:stylesheet>

    Contents of
    2)myxsl.xsl

    <xsl:variable name="Mapplicationtoc1">About MyXSL</xsl:variable>
    <some more such messages>

    Now in the output I want "About MyXSL" to be displayed after
    applying the templates for Book.
    This is some thing like "pointer to pointer". I want to retrieve
    the book name which is "Mapplicationtoc1" and I want the value of
    variable named Mapplicationtoc1. This variable is present in myxsl.xsl.

    What is the solution for this? I goggled a bit on this and got that
    *[local-name() = $tempMsg] should be used but this does not work in my
    case.

    Waiting for reply
    Regards,
    Sucheta Phatak,
     
    , Sep 20, 2005
    #1
    1. Advertising

  2. Joris Gillis Guest

    Hi,

    Tempore 13:11:23, die Tuesday 20 September 2005 AD, hinc in foro {comp.text.xml} scripsit <>:

    > Now in the output I want "About MyXSL" to be displayed after
    > applying the templates for Book.
    > This is some thing like "pointer to pointer". I want to retrieve
    > the book name which is "Mapplicationtoc1" and I want the value of
    > variable named Mapplicationtoc1. This variable is present in myxsl.xsl.


    This is not possible in XSLT. You cannot possible call variables indirectly.

    Try to think of another workaround. Here's some inspiration:

    1) a.xsl

    <xsl:template match="abc:Book">
    <xsl:value-of select="$message[@name=current()/@name]"/>
    </xsl:template>

    2) myxsl.xsl

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    exclude-result-prefixes="myvar"
    xmlns:myvar="myVariables">
    <xsl:eek:utput method="xml" indent="yes"/>

    <myvar:map xmlns="">
    <message name="Mapplicationtoc1">About MyXSL</message>
    <!-- some more such messages -->
    </myvar:map>

    <xsl:variable name="message"
    select="document('')/xsl:stylesheet/myvar:map/message"/>

    </xsl:stylesheet>

    regards,
    --
    Joris Gillis (http://users.telenet.be/root-jg/me.html)
    Don't send spam. I don't like it and it is illegal.
     
    Joris Gillis, Sep 20, 2005
    #2
    1. Advertising

  3. Guest

    Thanks Joris,

    That solved my problem.

    Regards,
    Sucheta.

    Joris Gillis wrote:
    > Hi,
    >
    > Tempore 13:11:23, die Tuesday 20 September 2005 AD, hinc in foro {comp.text.xml} scripsit <>:
    >
    > > Now in the output I want "About MyXSL" to be displayed after
    > > applying the templates for Book.
    > > This is some thing like "pointer to pointer". I want to retrieve
    > > the book name which is "Mapplicationtoc1" and I want the value of
    > > variable named Mapplicationtoc1. This variable is present in myxsl.xsl.

    >
    > This is not possible in XSLT. You cannot possible call variables indirectly.
    >
    > Try to think of another workaround. Here's some inspiration:
    >
    > 1) a.xsl
    >
    > <xsl:template match="abc:Book">
    > <xsl:value-of select="$message[@name=current()/@name]"/>
    > </xsl:template>
    >
    > 2) myxsl.xsl
    >
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > exclude-result-prefixes="myvar"
    > xmlns:myvar="myVariables">
    > <xsl:eek:utput method="xml" indent="yes"/>
    >
    > <myvar:map xmlns="">
    > <message name="Mapplicationtoc1">About MyXSL</message>
    > <!-- some more such messages -->
    > </myvar:map>
    >
    > <xsl:variable name="message"
    > select="document('')/xsl:stylesheet/myvar:map/message"/>
    >
    > </xsl:stylesheet>
    >
    > regards,
    > --
    > Joris Gillis (http://users.telenet.be/root-jg/me.html)
    > Don't send spam. I don't like it and it is illegal.
     
    , Sep 21, 2005
    #3
    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. Karsten Weinert
    Replies:
    3
    Views:
    1,011
    Karsten Weinert
    Jul 5, 2004
  2. MC
    Replies:
    1
    Views:
    7,265
    David Carlisle
    Mar 24, 2005
  3. Replies:
    1
    Views:
    3,612
    A. Bolmarcich
    May 27, 2005
  4. Brian Stubblefield

    struct and multiple indirection for a variable

    Brian Stubblefield, May 24, 2004, in forum: C Programming
    Replies:
    4
    Views:
    484
    Brian Stubblefield
    May 25, 2004
  5. Replies:
    2
    Views:
    9,277
    Martin Honnen
    Sep 5, 2006
Loading...

Share This Page