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 January 12th, 2005, 11:48 AM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default select childnode of a node with xmlns:xsl attribut

I have the following XML

<?xml version="1.0" encoding="windows-1252"?>
<root>
  <xform id = "Nwb Incident Management" xmlns="http://www.w3.org/2000/xforms">
    <module>
      <value1>test</value1>
      <value2>test</value2>
    </module>
  </xform>
</root>

I want to select the root node
    then the module, so I have to pass the xform node

but I can not select module because the xform node could not be found. when I remove the 'xmlns="http://www.w3.org/2000/xforms"' out of the xml and it works fine.

This is my code

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" version="1.0" indent="yes" />

                <xsl:template match = "/" >
                        <xsl:apply-templates select = "root"/>
                </xsl:template>

                <xsl:template match = "root" >
        <order_list>
                <xsl:apply-templates select="xform"/>
        </order_list>
                </xsl:template>

                <xsl:template match="xform" >
                        <xsl:apply-templates select = "module"/>
                </xsl:template>
 
Old January 12th, 2005, 11:57 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

http://www.dpawson.co.uk/xsl/sect2/N...tml#d6408e1012



--

Joe (Microsoft MVP - XML)
 
Old January 12th, 2005, 11:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

To select a node that's in a namespace, you need to use a prefix. Any prefix will do so long as it's bound to the right namespace. E.g.

<xsl:apply-templates select="x:xform" xmlns:x="http://www.w3.org/2000/xforms"/>

You would normally declare this namespace on the xsl:stylesheet element because you will probably be using it all over the place. Note that the children of the xform element are also in this namespace.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 13th, 2005, 12:29 PM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you all!!!

This is what I was looking for.
It is working perfect, after 2 weeks of trying.





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
Copy one node to another in XSL hugoscp XML 5 September 14th, 2006 09:40 AM
xsl using variable on a node Debiprasad XSLT 1 June 22nd, 2006 12:20 PM
attribute xmlns added in included xsl Kabe XSLT 6 November 23rd, 2004 12:24 PM





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