Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old August 4th, 2006, 10:21 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default Another Document ( ) Function Question

Hi Again,

How do I reference an element with an ID attribute? Right now the following code pulls ALL the <Para> elements. Say i want to pull the <Para> with an ID attribute of id="shareme"?

Code:
    <xsl:template match="JBU:share">
        <span style="background-color:red; ">
            <xsl:value-of select="document('source2.xml')/JBU:Book/JBU:Chapter/JBU:Sec1/JBU:sec2/JBU:Para"/>
            <xsl:apply-templates/>
        </span>
    </xsl:template


 
Old August 4th, 2006, 10:26 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Simplest is

select="document('source2.xml')/JBU:Book/JBU:Chapter/JBU:Sec1/JBU:sec2/JBU:Para[@id='shareme']"

If you're confident it really is an ID attribute, that is, it's marked as an ID attribute in the DTD and notified by the parser as such, then you can do

In 2.0:

<xsl:value-of select="document('source2.xml')/id('shareme')"/>

In 1.0:
<xsl:for-each select="document('source2.xml')">
  <xsl:value-of select="id('shareme')"/>
</xsl:for-each>

The for-each here doesn't do any iteration, it just changes the context node.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 4th, 2006, 10:45 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Michael,

Thanks again.... I am hooked. This is so powerful.

Bones







Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt document function.. maddukuri XSLT 8 May 16th, 2008 06:31 AM
Document Function Atribute bonekrusher XSLT 2 September 26th, 2006 05:44 PM
Document ( ) Function bonekrusher XSLT 5 August 4th, 2006 08:01 AM
How to use document() function jacob XSLT 8 November 30th, 2005 08:58 PM
xslt 2.0 document function jkmyoung XSLT 2 November 18th, 2004 03:21 PM





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