Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 28th, 2008, 04:47 PM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default accessing elements using document() function

Hi,

I am using the following xslt:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <xsl:copy-of select="document('testFile.xml')"/>
        <xsl:copy-of select="document('testFile.xml')/testData/city"/>
        <xsl:value-of select="document('testFile.xml')/testData/city"/>
    </xsl:template>
</xsl:stylesheet>

testFile.xml looks like this:

<testData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://someaddress.com/">
    <city>New York</city>
    <state>New York</state>
    <country>United States</country>
</testData>


the output I am getting looks like this:

<testData xmlns="http://someaddress.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <city>New York</city>
    <state>New York</state>
    <country>United States</country>
</testData>

The problem I am having is that the second and third lines inside my xsl:template are not producing any results. When I remove the namespace declarations from testFile.xml everything works as expected. So how can I get my expected results without making any modifications to testFile.xml? Thanks

Reply With Quote
  #2 (permalink)  
Old February 28th, 2008, 05:49 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:template match="/" xmlns:t="http://someaddress.com/">
        <xsl:copy-of select="document('testFile.xml')"/>
        <xsl:copy-of select="document('testFile.xml')/t:testData/t:city"/>
        <xsl:value-of select="document('testFile.xml')/t:testData/t:city"/>
    </xsl:template>

(see the sticky post at the start of this forum for more info)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old February 28th, 2008, 07:39 PM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. That worked!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing elements in an XML document dlorenz XSLT 0 August 7th, 2007 05:28 PM
Accessing elements of an Array object abdulqadirpk VB How-To 1 April 2nd, 2007 11:13 AM
convert elements based on place in document jefke XSLT 2 May 17th, 2004 05:32 AM
Accessing word document from VB Prasanna VB How-To 3 January 20th, 2004 05:20 AM



All times are GMT -4. The time now is 07:50 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.