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 April 18th, 2006, 08:22 PM
Jza Jza is offline
Registered User
 
Join Date: Apr 2006
Location: Villahermosa, Brooklyn, Birminham, Bucharest, , USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Jza Send a message via AIM to Jza Send a message via MSN to Jza Send a message via Yahoo to Jza
Default Removing nodes with an XSLT

I got an xml which I want to modify into a simpler one, the XML in question is the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE toolbar:toolbar PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "toolbar.dtd">

<toolbar:toolbar xmlns:toolbar="http://openoffice.org/2001/toolbar"
 xmlns:xlink="http://www.w3.org/1999/xlink">
 <toolbar:toolbaritem xlink:href=".uno:OpenUrl" toolbar:visible=
"false"/>
 <toolbar:toolbaritem xlink:href=".uno:AddDirect" toolbar:helpid=
"5537"/>
 <toolbar:toolbaritem xlink:href=".uno:NewDoc" toolbar:visible=
"false" toolbar:helpid="5500"/>
 <toolbar:toolbaritem xlink:href=".uno:Open" toolbar:helpid=
"5501"/>
 <toolbar:toolbaritem xlink:href=".uno:Save" toolbar:helpid=
"5505"/>
 <toolbar:toolbaritem xlink:href=".uno:SaveAs" toolbar:visible=
"false" toolbar:helpid="5502"/>
 <toolbar:toolbaritem xlink:href=".uno:SendMail" toolbar:helpid=
"5331"/>
 <toolbar:toolbarseparator/>
 <toolbar:toolbaritem xlink:href=".uno:EditDoc" toolbar:helpid=
"6312"/>
 <toolbar:toolbarseparator/>
 <toolbar:toolbaritem xlink:href=".uno:ExportDirectToPDF" toolbar:helpid=
"6674"/>
 <toolbar:toolbaritem xlink:href=".uno:PrintDefault" toolbar:helpid=
"5509"/>
 <toolbar:toolbaritem xlink:href=".uno:PrintPreview" toolbar:helpid=
"5325"/>
 <toolbar:toolbarseparator/>
 <toolbar:toolbaritem xlink:href=".uno:SpellDialog" toolbar:helpid=
"20622"/>
 <toolbar:toolbaritem xlink:href=".uno:SpellOnline" toolbar:helpid=
"12021"/>
 <toolbar:toolbarseparator/>
 <toolbar:toolbaritem xlink:href=".uno:Cut" toolbar:helpid=
"5710"/>
 <toolbar:toolbaritem xlink:href=".uno:Copy" toolbar:helpid=
"5711"/>
 <toolbar:toolbaritem xlink:href=".uno:Paste" toolbar:helpid=
"5712"/>
 <toolbar:toolbaritem xlink:href=".uno:FormatPaintbrush" toolbar:helpid=
"5715"/>
 <toolbar:toolbarseparator/>
 <toolbar:toolbaritem xlink:href=".uno:Undo" toolbar:helpid=
"5701"/>
 <toolbar:toolbaritem xlink:href=".uno:Redo" toolbar:helpid=
"5700"/>
 <toolbar:toolbarseparator/>
 <toolbar:toolbaritem xlink:href=".uno:HyperlinkDialog" toolbar:helpid=
"5678"/>
 <toolbar:toolbaritem xlink:href=".uno:InsertTable" toolbar:helpid=
"20330"/>
 <toolbar:toolbaritem xlink:href=".uno:InsertDraw" toolbar:helpid=
"10244"/>
 <toolbar:toolbarseparator/>
 <toolbar:toolbaritem xlink:href=".uno:SearchDialog" toolbar:helpid=
"5961"/>
 <toolbar:toolbaritem xlink:href=".uno:Navigator" toolbar:helpid=
"10366"/>
 <toolbar:toolbaritem xlink:href=".uno:Gallery" toolbar:helpid=
"5960"/>
 <toolbar:toolbaritem xlink:href=".uno:ViewDataSourceBrowser" toolbar:helpid=
"6660"/>
 <toolbar:toolbaritem xlink:href=".uno:ControlCodes" toolbar:helpid=
"20224"/>
 <toolbar:toolbaritem xlink:href=".uno:Zoom" toolbar:helpid=
"10000"/>
 <toolbar:toolbarseparator/>
 <toolbar:toolbaritem xlink:href=".uno:HelpIndex"/>
 <toolbar:toolbaritem xlink:href=".uno:ExtendedHelp" toolbar:visible=
"false" toolbar:helpid="5402"/>
</toolbar:toolbar>

I want to reduce it like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE toolbar:toolbar PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0
//EN" "toolbar.dtd">
<toolbar:toolbar xmlns:toolbar="
http://openoffice.org/2001/toolbar" xmlns:xlink="
http://www.w3.org/1999/xlink">
 <toolbar:toolbaritem xlink:href=".uno:AddDirect"
 toolbar:helpid="5537"/>
 <toolbar:toolbaritem xlink:href=
".uno:NewDoc" toolbar:visible="false" toolbar:helpid=
"5500"/>
 <toolbar:toolbaritem xlink:href=".uno:Open"
 toolbar:helpid="5501"/>
 <toolbar:toolbaritem xlink:href=
".uno:Save" toolbar:helpid="5505"/>
 <toolbar:toolbarseparator/>
 <toolbar:toolbaritem
 xlink:href=".uno:ExportDirectToPDF" toolbar:helpid=
"6674"/>
 <toolbar:toolbaritem xlink:href=".uno:PrintDefault"
 toolbar:helpid="5509"/>
 <toolbar:toolbaritem xlink:href=
".uno:PrintPreview" toolbar:helpid="5325"/>
 <toolbar:toolbarseparator/>

<toolbar:toolbaritem xlink:href=".uno:Cut" toolbar:helpid=
"5710"/>
 <toolbar:toolbaritem xlink:href=".uno:Copy"
 toolbar:helpid="5711"/>
 <toolbar:toolbaritem xlink:href=
".uno:Paste" toolbar:helpid="5712"/>
 <toolbar:toolbaritem
 xlink:href=".uno:FormatPaintbrush" toolbar:helpid="5715"/>

 <toolbar:toolbarseparator/>
 <toolbar:toolbaritem xlink:href=".uno:Undo"
 toolbar:helpid="5701"/>
 <toolbar:toolbaritem xlink:href=
".uno:Redo" toolbar:helpid="5700"/>
 <toolbar:toolbarseparator/>
 <toolbar:toolbaritem
 xlink:href=".uno:InsertDraw" toolbar:helpid=
"10244"/>
 <toolbar:toolbarseparator/>
</toolbar:toolbar>


Alexandro Colorado
Co-Leader for OpenOffice.org Project
Reply With Quote
  #2 (permalink)  
Old April 19th, 2006, 02:48 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: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,947
Thanks: 0
Thanked 288 Times in 283 Posts
Default

When posting questions, try and apply the 10-second test: in ten seconds, the reader is going to have to decide (a) whether he is capable of answering this question, and (b) whether it's worth his time.

I'm not going to study your input and output to spot the differences, I have better things to do with my time. You could easily construct the question in a way that saves me this effort.

The general strategy for deleting nodes is a stylesheet with two template rules: a general rule that copies nodes unchanged (google for "identity template) and a specific rule that matches the nodes you want to delete:

<xsl:template match="node-to-be-removed"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old April 19th, 2006, 10:06 AM
Jza Jza is offline
Registered User
 
Join Date: Apr 2006
Location: Villahermosa, Brooklyn, Birminham, Bucharest, , USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Jza Send a message via AIM to Jza Send a message via MSN to Jza Send a message via Yahoo to Jza
Default

Sorry, I guess an easier way to present the example of what I want to do is not plugging the whole output.

Here it is again:

Original XML:
Code:
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE toolbar:toolbar PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "toolbar.dtd">
3 <toolbar:toolbar xmlns:toolbar="http://openoffice.org/2001/toolbar"
†xmlns:xlink="http://www.w3.org/1999/xlink">
4    <toolbar:toolbaritem xlink:href=".uno:OpenUrl" toolbar:visible=
"false"/>
5    †<toolbar:toolbaritem xlink:href=".uno:AddDirect" toolbar:helpid=
"5537"/>
6</toolbar:toolbar>
Final XML:
Code:
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE toolbar:toolbar PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "toolbar.dtd">
3 <toolbar:toolbar xmlns:toolbar="http://openoffice.org/2001/toolbar"
†xmlns:xlink="http://www.w3.org/1999/xlink">
4    <toolbar:toolbaritem xlink:href=".uno:OpenUrl" toolbar:visible=
"true"/>
6</toolbar:toolbar>
Here, the XSLT eliminate the line no. 5:
    †<toolbar:toolbaritem xlink:href=".uno:AddDirect" toolbar:helpid=
"5537"/>

Alternatively I would link to as opposed to delete the node, just change the attribute to true/false on OpenURL (fist node).
.... xlink:href=".uno:OpenUrl" toolbar:visible="true"/>

Hope this is easier to understand.

Alexandro Colorado
Co-Leader for OpenOffice.org Project
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
XSLT 1.0: Looping through nodes kwilliams XSLT 4 December 1st, 2008 05:21 PM
XML + XSLT Compare Nodes tommyready XSLT 5 September 5th, 2007 03:18 AM
Removing duplicate nodes post-process QuickSilver002 XSLT 3 April 4th, 2007 03:47 PM
XPATH removing nodes from file?? dparsons ASP.NET 2.0 Professional 1 February 27th, 2007 04:37 PM
XSLT for Variable Child Nodes jlagedo XSLT 2 September 10th, 2006 03:00 AM



All times are GMT -4. The time now is 05:32 PM.


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