[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: keep 2nd chapter element
Hi Jim, It seems to me _a grouping problem_, which can be solved by Muenchian method.. The XSL for this would be -- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:key name="group-by-id" match="chapter" use="@id" /> <xsl:template match ="/A"> <xsl:for-each select="chapter"> <xsl:if test="(generate-id(.) = generate-id( key('group-by-id', @id)[1])) and not(@value = '0')"> <xsl:copy-of select="." /> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> If the above XSL is applied to the XML -- <?xml version="1.0" encoding="UTF-8"?> <A> <chapter id="BCV-MRK-0" value="0" /> <chapter id="BCV-MRK-0" value="0" /> <chapter id="BCV-MRK-1" value="1" /> <chapter id="BCV-MRK-1" value="1" /> <chapter id="BCV-MRK-1" value="1" /> <chapter id="BCV-MRK-2" value="2" /> <chapter id="BCV-MRK-2" value="2" /> <chapter id="BCV-MRK-2" value="2" /> <chapter id="BCV-MRK-2" value="2" /> <chapter id="BCV-MRK-3" value="3" /> <chapter id="BCV-MRK-3" value="3" /> <chapter id="BCV-MRK-3" value="3" /> <chapter id="BCV-MRK-3" value="3" /> </A> (I have introduced a <A> tag to make the XML well-formed, and have removed keep tags) It produces output -- <chapter id="BCV-MRK-1" value="1"/> <chapter id="BCV-MRK-2" value="2"/> <chapter id="BCV-MRK-3" value="3"/> I hope, this solution _was_ required.. I am not sure, whether Michael Kay's solution solved the problem.. I observed that the XPath expression Michael Kay wrote, produced a different ouput. Regards, Mukul --- Jim_Albright@xxxxxxxxxxxx wrote: > reducing the problem to bare bones I want to keep > only some of the > "chapter" elements and toss the rest: > <chapter id="BCV-MRK-0" value="0" > keep="no"/> > <chapter id="BCV-MRK-0" value="0" > keep="no"/> > <chapter id="BCV-MRK-1" value="1" > keep="yes"/> > <chapter id="BCV-MRK-1" value="1" > keep="no"/> > <chapter id="BCV-MRK-1" value="1" > keep="no"/> > <chapter id="BCV-MRK-2" value="2" > keep="no"/> > <chapter id="BCV-MRK-2" value="2" > keep="yes"/> > <chapter id="BCV-MRK-2" value="2" > keep="no"/> > <chapter id="BCV-MRK-2" value="2" > keep="no"/> > <chapter id="BCV-MRK-3" value="3" > keep="no"/> > <chapter id="BCV-MRK-3" value="3" > keep="yes"/> > <chapter id="BCV-MRK-3" value="3" > keep="no"/> > <chapter id="BCV-MRK-3" value="3" > keep="no"/> > > I have added the keep attribute by hand to show > which "chapter"s to keep > so I should end with > <chapter id="BCV-MRK-1" value="1" > keep="yes"/> > <chapter id="BCV-MRK-2" value="2" > keep="yes"/> > <chapter id="BCV-MRK-3" value="3" > keep="yes"/> > > > <xsl:template match="chapter" > > <xsl:choose> > <!--...... if chapter is zero then toss > .....--> > <xsl:when test="@value='0'"> > <!--...... remove chapter 0 > .....--> > </xsl:when> > <!--...... if very first chapter 1 in book > then keep .....--> > <xsl:when test="@value='1' and > preceding::chapter[not(@value='1')]"> > <xsl:call-template > name="copy-current-node"/> > </xsl:when> > <!--...... if second occurrence of same > value and value is not 1 > then keep it .....--> > <xsl:when test=""><!-- not working > yet--> > <xsl:call-template > name="copy-current-node"/> > </xsl:when> > <xsl:otherwise> > <!--...... remove duplicate > chapter .....--> > </xsl:otherwise> > </xsl:choose> > </xsl:template> > > > Jim Albright > 704 843-0582 > Wycliffe Bible Translators > > > > XSL-List info and archive: > http://www.mulberrytech.com/xsl/xsl-list > __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|