Subject: Re: [xsl] Display text and all the following nodes except <anchor> and <pb> From: Syd Bauman <Syd_Bauman@xxxxxxxxx> Date: Thu, 18 Sep 2008 04:05:34 -0400 |
Ooops ... change "h1" to "head" in my discussion paragraph and match. But more importantly, George's solution (just posted -- match head/anchor and head/pb and ignore them) seems more elegant than mine. Nonetheless, just to get it recorded properly: --------- (524) Plod-2 /tmp @ 04:02:06 ->cat Untitled2.xml # INPUT FILE <?xml version="1.0" encoding="UTF-8"?> <duck> <head>O<sCap>FFICERS</sCap> of <person>the</person> R<sCap>EGIMENT</sCap> of I<sCap>NFANTRY</sCap><anchor id="J" >anchor</anchor><pb n="2">2</pb> </head> <anchor id="c">anchor1</anchor> </duck> (525) Plod-2 /tmp @ 04:02:07 ->cat Untitled1.xsl # XSLT FILE <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- match root, process its children --> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <!-- identity transform of anything not otherwise matched below --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <!-- process <head> specially: ignore child <anchor> or <pb> --> <xsl:template match="head"> <xsl:element name="h1"> <xsl:apply-templates select="@* |*[not(name(.)='anchor' or name(.)='pb')] |text() |comment() |processing-instruction()" /> </xsl:element> </xsl:template> <!-- phrase-level elements become <span> --> <xsl:template match="sCap|person"> <xsl:element name="span"> <xsl:attribute name="class"><xsl:value-of select="name(.)"/></xsl:attribute> <xsl:apply-templates/> <!-- presume input has no span= attribute --> </xsl:element> </xsl:template> <!-- <anchor>s become <a>s --> <xsl:template match="anchor"> <xsl:element name="a"> <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute> <xsl:apply-templates/> <!-- presume input has no id= attribute --> </xsl:element> </xsl:template> </xsl:stylesheet> (526) Plod-2 /tmp @ 04:02:08 ->xsltproc Untitled1.xsl Untitled2.xml # OUTPUT <?xml version="1.0"?> <duck> <h1>O<span class="sCap">FFICERS</span> of <span class="person">the</span> R<span class="sCap">EGIMENT</span> of I<span class="sCap">NFANTRY</span> </h1> <a name="c">anchor1</a> </duck> (527) Plod-2 /tmp @ 04:02:10 -> ---------
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Display text and all the , Syd Bauman | Thread | Re: [xsl] Display text and all the , J. S. Rawat |
Re: [xsl] Display text and all the , Syd Bauman | Date | Re: [xsl] Display text and all the , J. S. Rawat |
Month |