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 September 6th, 2006, 07:50 AM
Registered User
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Extracting Subset and Modifying Attribute

I am attempting to extract an XML document wrapped in an envelope and modify one tag to include namespace information. Here is a portion of the document:


How can I extract only the <Order> to </Order> portion of the document(exactly) while altering the Order tag itself to say
 <Order xmlns="rrn:org.xcbl:schemas/xcbl/v3_0/xcbl30.xsd">

I keep getting all tags modified when I try to use <xsl:if test="@name = Order"></xsl:if> in concert with <xsl:copy-of select="@*"/>.

I am very new to this.
I am attempting to copy

Old September 6th, 2006, 08:41 AM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

Changing <Order> to <Order xmlns="rrn:org.xcbl:schemas/xcbl/v3_0/xcbl30.xsd"> is effectively renaming the element, because the element name has two parts, a local part and a namespace URI. I imagine you also want to rename all the children of the Order so they are also in this namespace.

To do this you want a recursive descent template like this:

<xsl:template match="*" mode="rename">
  <xsl:element name="{local-name()}" namespace="rrn:org.xcbl:schemas/xcbl/v3_0/xcbl30.xsd">
    <xsl:apply-templates mode="rename"/>

and then invoke this on the Order that you want to "copy" (it's not actually a copy at all, because you are changing the name of every element).

Note that if you create the elements with the correct names, the namespace declarations will look after themselves.

>I keep getting all tags modified when I try to use <xsl:if test="@name = Order"></xsl:if> in concert with <xsl:copy-of select="@*"/>.

You've got me completely puzzled there. Why are you using instructions that refer to attributes when your source document contains no attributes?

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting ancestor by providing the attribute eruditionist XSLT 6 September 9th, 2008 08:12 AM
Extracting subset of XML using XSLT sentah XSLT 3 September 3rd, 2008 02:44 PM
Extracting a number range from tag attribute group maikm XSLT 6 August 25th, 2008 04:54 PM
extracting attribute value hag XSLT 1 March 3rd, 2008 03:16 AM
modifying src attribute jtnw XSLT 1 January 20th, 2005 05:08 AM

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