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 April 18th, 2006, 08:22 PM
Jza Jza is offline
Registered User
 
Join Date: Apr 2006
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
 
Old April 19th, 2006, 02:48 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old April 19th, 2006, 10:06 AM
Jza Jza is offline
Registered User
 
Join Date: Apr 2006
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





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT 1.0: Looping through nodes kwilliams XSLT 4 December 1st, 2008 06: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 05:37 PM
XSLT for Variable Child Nodes jlagedo XSLT 2 September 10th, 2006 03:00 AM





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