Subject: Re: [xsl] Selectively convert Attributes to child Elements From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 18 May 2009 21:07:33 -0400 |
Below illustrates how one could address your requirement. A quick review of the result looks like it is what you want.
And my quick review was wrong, as I missed the elements ... when hacking your original I left in a line I shouldn't have.
You might find the one below more useful, as this one actually constitutes the elements.
T:\ftemp>type maestro.xml <?xml version="1.0" encoding="UTF-8"?> <buckets siteid="mysiteid" version="1.0"> <bucket priority="4" bucketid="12348" title="Sports" displaytitle="Sports" link="/sections/sports/" target="_blank" display="1"> <nav> <item priority="1" title="Baseball" displaytitle="Baseball" link="/sections/sports/baseball/" description="Baseball 411" display="1"/> <item priority="2" title="Football" displaytitle="Football" link="/sections/sports/football/" description="" display="1"/> </nav> <contentInclude priority="1" max="3" display="1"> <item catid="2345" catname="Sports" prefix="" display="1"/> </contentInclude> <contentInclude type="daytime" priority="2" max="2" display="1"> <item catname="sports" display="1"/> </contentInclude> <contentInclude type="blog" priority="3" max="2" display="1"> <item catname="coolblog" prefix="Cool: " display="1"/> <item catname="soundblog" prefix="Sounds: " display="1"/> </contentInclude> <bucketBottomLink title="More Sports »" link="/sections/entertainment/" display="1"/> </bucket> <bucket priority="3" bucketid="12347" title="Promotions" displaytitle="" description="This is the Promotions bucket" link="" display="1" tags="promos,promotions,nonpublic"> <contentInclude priority="1" display="1"> <item catid="5678" catname="Promos" prefix="" display="1"/> </contentInclude> </bucket> <bucketLists> <bucketList priority="4" bucketListid="4" location="homepage" title="Entertainment List" displaytitle="Entertainment Junkie" display="1" tags="entertainment,fun"> <bucketListItem priority="1" bucketid="34572" title="Entertainment" display="1"/> <bucketListItem priority="5" bucketid="34576" type="blog" title="artsblog" items="7" display="1"/> </bucketList> <bucketList priority="5" bucketListid="5" location="homepage" title="Nerd" displaytitle="Nerd's List of Lists" display="1" tags="tech,technology,gadgets,nerd,geek"> <bucketListItem priority="1" bucketid="34577" title="Science & Technology" display="1"/> <bucketListItem priority="4" bucketid="34582" type="blog" title="nerdblog" items="7" display="1"/> </bucketList> </bucketLists> </buckets>
T:\ftemp>call xslt maestro.xml maestro.xsl <?xml version="1.0" encoding="utf-8"?> <buckets siteid="mysiteid" version="1.0"> <bucket priority="4" bucketid="12348" link="/sections/sports/" target="_blank" display="1"> <title>Sports</title> <displaytitle>Sports</displaytitle> <nav> <item priority="1" link="/sections/sports/baseball/" display="1"> <title>Baseball</title> <displaytitle>Baseball</displaytitle> <description>Baseball 411</description> </item> <item priority="2" link="/sections/sports/football/" display="1"> <title>Football</title> <displaytitle>Football</displaytitle> <description/> </item> </nav> <contentInclude priority="1" max="3" display="1"> <item catid="2345" display="1"> <catname>Sports</catname> <prefix/> </item> </contentInclude> <contentInclude type="daytime" priority="2" max="2" display="1"> <item display="1"> <catname>sports</catname> </item> </contentInclude> <contentInclude type="blog" priority="3" max="2" display="1"> <item display="1"> <catname>coolblog</catname> <prefix>Cool: </prefix> </item> <item display="1"> <catname>soundblog</catname> <prefix>Sounds: </prefix> </item> </contentInclude> <bucketBottomLink link="/sections/entertainment/" display="1"> <title>More Sports B;</title> </bucketBottomLink> </bucket> <bucket priority="3" bucketid="12347" link="" display="1" tags="promos,promotions,nonpublic"> <title>Promotions</title> <displaytitle/> <description>This is the Promotions bucket</description> <contentInclude priority="1" display="1"> <item catid="5678" display="1"> <catname>Promos</catname> <prefix/> </item> </contentInclude> </bucket> <bucketLists> <bucketList priority="4" bucketListid="4" location="homepage" display="1" tags="entertainment,fun"> <title>Entertainment List</title> <displaytitle>Entertainment Junkie</displaytitle> <bucketListItem priority="1" bucketid="34572" display="1"> <title>Entertainment</title> </bucketListItem> <bucketListItem priority="5" bucketid="34576" type="blog" items="7" display="1"> <title>artsblog</title> </bucketListItem> </bucketList> <bucketList priority="5" bucketListid="5" location="homepage" display="1" tags="tech,technology,gadgets,nerd,geek"> <title>Nerd</title> <displaytitle>Nerd's List of Lists</displaytitle> <bucketListItem priority="1" bucketid="34577" display="1"> <title>Science & Technology</title> </bucketListItem> <bucketListItem priority="4" bucketid="34582" type="blog" items="7" display="1"> <title>nerdblog</title> </bucketListItem> </bucketList> </bucketLists> </buckets> T:\ftemp>type maestro.xsl <!-- AttrToElement.xsl: Turn all attributes into subelements --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:strip-space elements="*"/> <xsl:output indent="yes"/>
<xsl:template match="*"> <xsl:copy> <xsl:apply-templates select="@*" mode="preserve"/> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
<!--handle attributes at the time they are being preserved--> <!--ignore these--> <xsl:template mode="preserve" match="@title|@displaytitle|@description| @catname|@prefix|@text"/> <!--preserve these--> <xsl:template mode="preserve" match="@*"> <xsl:copy/> </xsl:template>
<!--handle attributes at the time they are being converted--> <!--convert these--> <xsl:template match="@title|@displaytitle|@description| @catname|@prefix|@text"> <xsl:element name="{name()}"> <xsl:value-of select="."/> </xsl:element> </xsl:template> <!--ignore these--> <xsl:template match="@*"/>
-- XSLT/XSL-FO/XQuery hands-on training - Los Angeles, USA 2009-06-08 Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Selectively convert Attri, G. Ken Holman | Thread | Re: [xsl] Selectively convert Attri, The Web Maestro |
Re: [xsl] Selectively convert Attri, G. Ken Holman | Date | Re: [xsl] Selectively convert Attri, The Web Maestro |
Month |