|
Subject:
|
Removing nodes with an XSLT
|
|
Posted By:
|
Jza
|
Post Date:
|
4/18/2006 8:22:32 PM
|
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 By:
|
mhkay
|
Reply Date:
|
4/19/2006 2:48:21 AM
|
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 By:
|
Jza
|
Reply Date:
|
4/19/2006 10:06:55 AM
|
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:
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:
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
|