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 May 4th, 2010, 02:51 PM
Registered User
 
Join Date: May 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default xslt to remove tag

Hi,

I am new to XSLT and I'm trying to change the following XML
<concept>
<title>title</title>
<conbody>
<section>
<p>psection</p>
<q>quotation</q>
</section>
</conbody>
</concept>

to

<concept>
<title>title</title>
<conbody>
<section>
<p>psection</p>
"quotation"
</section>
</conbody>
</concept>

which is basically change the <q> tags to actual quotations.
How can I do this?

Thanks in Advance
 
Old May 4th, 2010, 03:42 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Write a stylesheet with two template rules.

The identity template for elements that you don't want to change:

Code:
<xsl:template match="*">
  <xsl:copy>
     <xsl:copy-of select="@*"/>
     <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>
and a special rule for the elements you do want to change:

Code:
<xsl:template match="q">"<xsl:apply-templates/>"</xsl:template>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old May 5th, 2010, 04:03 PM
Registered User
 
Join Date: May 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Surprisingly it does not change the <q> tags to quotations. Why might that be? Is there something wrong in my eclipse configuration or there might be a parser issue?

Thanks
 
Old May 5th, 2010, 05:47 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If it doesn't work, then there's something you haven't told us. Often the thing that people forget to tell us is that the input is in a namespace - but that's just one possible guess.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old May 6th, 2010, 09:24 AM
Registered User
 
Join Date: May 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it is in fact in a namespace....is that why is isnt working? How can we fix this?
 
Old May 6th, 2010, 09:29 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Code:
<xsl:template xmlns:foo="http://example.com/foo" match="foo:q">"<xsl:apply-templates/>"</xsl:template>
Replace http://example.com/foo with the namespace URI the "q" element is in in your input
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Increment tag by 1 using XSLT Divya XSLT 10 April 13th, 2010 05:39 AM
Remove Namespace from tag using tag nisargmca XSLT 9 March 19th, 2010 06:40 AM
Remove Namespace from root tag using xslt namespce prefix nisargmca XSLT 0 February 24th, 2010 01:08 AM
Help!!::XSLT Transformation to remove repetition i techno_savvy81 XML 0 September 19th, 2007 05:01 AM
xslt for each and attribute tag desse XSLT 1 May 24th, 2006 08:01 AM





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