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 February 28th, 2008, 04:47 PM
Registered User
 
Join Date: Feb 2008
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

 
Old February 28th, 2008, 05:49 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old February 28th, 2008, 07:39 PM
Registered User
 
Join Date: Feb 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. That worked!






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





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