Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL variable indirection

Reply
Thread Tools

XSL variable indirection

 
 
sucheta.phatak@gmail.com
Guest
Posts: n/a
 
      09-20-2005
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"
xmlnssl="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,

 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      09-20-2005
Hi,

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

> 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"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="myvar"
xmlns:myvar="myVariables">
<xslutput 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.
 
Reply With Quote
 
 
 
 
sucheta.phatak@gmail.com
Guest
Posts: n/a
 
      09-21-2005
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 <(E-Mail Removed)>:
>
> > 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"
> xmlnssl="http://www.w3.org/1999/XSL/Transform"
> exclude-result-prefixes="myvar"
> xmlns:myvar="myVariables">
> <xslutput 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:sort using an xsl:variable as the sort key jobooker@gmail.com XML 2 09-05-2006 03:51 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
[XSL] : use array variable in XSL stylesheet MC XML 1 03-24-2005 10:41 AM
Difference between xsl:param and xsl:variable? Karsten Weinert XML 3 07-05-2004 04:58 PM
struct and multiple indirection for a variable Brian Stubblefield C Programming 4 05-25-2004 07:14 PM



Advertisments