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 Display Modes
  #1 (permalink)  
Old May 14th, 2007, 04:30 AM
Authorized User
 
Join Date: Apr 2007
Location: guntur, ap, India.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Converting Source Xml into Target Xml Using XSL.

Hi ,

i have a source xml . i need a xsl for this xml . My target xml should contain only the local-names() of source .It means xsl should remove all the name space binding s.

In my source xml i have elements as well as attributes . My xsl should generate target xml with out any namespace bindings.For attributes also i need to consider only the local-names().

A. Sasi
__________________
A. Sasi
Reply With Quote
  #2 (permalink)  
Old May 14th, 2007, 06:50 AM
mhkay's Avatar
Wrox Author
Points: 18,392, Level: 59
Points: 18,392, Level: 59 Points: 18,392, Level: 59 Points: 18,392, Level: 59
Activity: 75%
Activity: 75% Activity: 75% Activity: 75%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,947
Thanks: 0
Thanked 288 Times in 283 Posts
Default

Write a stylesheet containing two template rules:

 <xsl:template match="*">
  <xsl:element name="{local-name()}">
    <xsl:apply-templates select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
 </xsl:template>

 <xsl:template match="@*">
  <xsl:attribute name="{local-name()}"
    <xsl:value-of select="."/>
  </xsl:attribute>
 </xsl:template>

Note that this will remove any namespaces on attributes such as xml:space and xsi:type where the namespace may be essential to the meaning.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old May 14th, 2007, 09:37 AM
Authorized User
 
Join Date: Apr 2007
Location: guntur, ap, India.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,
Thanks very much for the help . Its working .
Bottom line is this style sheet will remove all the namespace bindings for elements as well as attributes of elements.

i have a small doubt on how the style sheet works. Can you please tell me .

1)<xsl:template match="*">
  <xsl:element name="{local-name()}">
    <xsl:apply-templates select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
 </xsl:template>

match="*" means for all the elements.

why there are two xsl:apply-templates?
2)<xsl:template match="@*">
  <xsl:attribute name="{local-name()}"
    <xsl:value-of select="."/>
  </xsl:attribute>
 </xsl:template>

This is take the local-name() for all the attributes of a element .
Where are we specifying for all the elements apply this ?

These are my doubts . i asked you because i want to know how it works internally .

Thanks & Regards,
SAsi.A

A. Sasi
Reply With Quote
  #4 (permalink)  
Old May 14th, 2007, 10:54 AM
mhkay's Avatar
Wrox Author
Points: 18,392, Level: 59
Points: 18,392, Level: 59 Points: 18,392, Level: 59 Points: 18,392, Level: 59
Activity: 75%
Activity: 75% Activity: 75% Activity: 75%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,947
Thanks: 0
Thanked 288 Times in 283 Posts
Default

The line

<xsl:apply-templates select="@*"/>

applies template rules to all the attribute nodes. It's unusual to use apply-templates for attribute nodes, but it's perfectly legal, and it's useful when you want to apply generic processing. This will be matched by the second template rule with match="@*".

The other <xsl:apply-templates/> processes all child nodes (which doesn't include attributes). These will be matched by the first template rule (recursively) for elements, and by the built-in template rules for text, comment, and PI nodes. (Actually this stylesheet will delete comments and PIs, if you don't want that, add template rules to match them and copy them).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools
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
Difficulties converting XML to XML using XSLT Reznik XSLT 7 June 3rd, 2008 05:45 AM
Converting xml to xsl leena XSLT 1 August 3rd, 2007 06:04 AM
How to: Xlate program in XML to target language? Philibuster XSLT 2 August 24th, 2006 10:25 AM
Converting XML to XML (making element mandatory) boondocksaint20 XSLT 8 April 28th, 2006 10:54 AM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM



All times are GMT -4. The time now is 03:16 PM.


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