Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 10th, 2008, 02:01 PM
Authorized User
 
Join Date: Oct 2007
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default value-of inside template match

I am having this really noobish problem wich i can't find the simple answer for :(

I have a translation in an xml document wich I put in the select of a apply-templates, this translation has an xml element in it called 'link'

Now i have a xsl:template match="link" wich get's called like it should.
In this template i select something from the root source with xsl:value-of. The value i select does exist, i checked. Though this value doesn't get applied in the template. I kinda know it must be a easy problem but i think it's too general to search for, i looked at numerous examples and they all do it like this.

  #2 (permalink)  
Old April 10th, 2008, 04:27 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi,

Please post a sample XML file, the psrt of the XSLT that you are having trouble with and desired output.

Regards,


  #3 (permalink)  
Old April 10th, 2008, 05:04 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There's a bug in your code.

If you show us your code, and its input, then we may be able to help you find it.

Do you really imagine we can find the bug without seeing the code?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #4 (permalink)  
Old April 13th, 2008, 10:05 AM
Authorized User
 
Join Date: Oct 2007
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well, i have this xml file which has the following node inside:

Code:
<intro>bla bla bla <link><url>gmail</url><text>Gmail</text></link> bla bla bla</intro>
i read in this file with the following xsl:

Code:
<xsl:variable name="xml.email" select="document('Translations/Email.xml')"/>
<xsl:variable name="lang.email" select="$xml.email/translations/info[lang($language)]" />
i call this 'text' with the following xsl:

Code:
<xsl:apply-templates select="$lang.email/intro" />
then i have this template which gets aplied:

Code:
<xsl:template match="link">
    <a>
        <xsl:attribute name="href">
            /email/<xsl:value-of select="url"/>/<xsl:value-of select="/source/pictureId"/>/<xsl:value-of select="/source/titleId"/>
        </xsl:attribute>
        <xsl:value-of select="text"/>
    </a>
</xsl:template>
the template does get called, but the 2 values inside (/source/pictureId and /source/titleId) aren't inserted, they are in the input xml though, i know this because when i do this, i get the right value from /source/pictureId:

Code:
<xsl:value-of select="/source/pictureId"/>
<xsl:apply-templates select="$lang.email/intro" />
so when i do the above, i see the value of /source/pictureId in front of my bla bla text.

Sorry for not posting the code, i didn't thought i had a bug but a silly beginner mistake

  #5 (permalink)  
Old April 13th, 2008, 10:11 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

So you have two XML input documents, the primary contaning a 'source' element, and a secondary you pull in with the document function. Use a global variable to store the root of the primary input document e.g.
Code:
<xsl:variable name="main-root" select="/"/>
then use that variable in your template:
Code:
<xsl:template match="link">
    <a>
        <xsl:attribute name="href">
            /email/<xsl:value-of select="url"/>/<xsl:value-of select="$main-root/source/pictureId"/>/<xsl:value-of select="$main-root/source/titleId"/>
        </xsl:attribute>
        <xsl:value-of select="text"/>
    </a>
</xsl:template>
--
  Martin Honnen
  Microsoft MVP - XML
  #6 (permalink)  
Old April 17th, 2008, 12:09 PM
Authorized User
 
Join Date: Oct 2007
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much, this works like a charm!



Similar Threads
Thread Thread Starter Forum Replies Last Post
Param in template match=" " iceandrews XSLT 2 May 7th, 2008 07:37 AM
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 06:24 AM
template m,atch doesnt match Tomi XSLT 1 March 9th, 2007 07:56 AM
xsl:template match 'overlapping' ? Kabe XSLT 1 February 25th, 2005 06:03 AM
help with xsl template match enT XSLT 9 September 24th, 2003 06:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.