XSL variable indirection

S

sucheta.phatak

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,
 
J

Joris Gillis

Hi,

Tempore 13:11:23 said:
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,
 
S

sucheta.phatak

Thanks Joris,

That solved my problem.

Regards,
Sucheta.

Joris said:
Hi,

Tempore 13:11:23 said:
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,
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top