Subject: RE: RE: [xsl] listing elements & sub-elements in a seqence - skiping From: cknell@xxxxxxxxxx Date: Wed, 26 Jul 2006 10:20:06 -0400 |
No need for grouping. No need for xsl:for-each. Although I suspect that you don't really want your output as text (even though that is what you show as the desired output), here is a stylesheet that produces the output as described. <?xml version="1.0"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:strip-space elements="*" /> <xsl:output method="text" indent="yes" encoding="UTF-8" /> <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template match="session"> <xsl:apply-templates /> </xsl:template> <xsl:template match="section[subsection]"> <xsl:value-of select="title" />. Appears at beginning of section <xsl:value-of select="title" />. <xsl:apply-templates select="subsection" /> </xsl:template> <xsl:template match="section[not(subsection)]"> <xsl:apply-templates /> </xsl:template> <xsl:template match="subsection"> <xsl:apply-templates /> </xsl:template> <xsl:template match="title"> <xsl:value-of select="." />.html </xsl:template> </xsl:stylesheet> -- Charles Knell cknell@xxxxxxxxxx - email -----Original Message----- From: Karl <call14@xxxxxxxxx> Sent: Wed, 26 Jul 2006 10:42:06 +0100 (BST) To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] listing elements & sub-elements in a seqence - skiping Thanks Charles. However, I think you overlooked a minor thing when mentioning [I have another q at the end. Pls have a look] --------- If you use: <xsl:apply-templates select="//Session/Section" /> you will get the same output as: <xsl:for-each select="//Section[not(SubSection)] | //Section/SubSection"/> or <xsl:for-each select="//Session/Section" /> ------ by writing "//Section[not(SubSection)] | //Section/SubSection?, What I am trying to achieve is - select section ONLY if there are NO ?subsection? i.e ignore those section?s that have subsection & - If there are subsections, then loop thro each subsection (ignoring section element) May be my sample xml is bad. So, I give a better example here [real xml have many other elements & contents]. Pls ignore any spell mistake or case mistake like section or Section. <session> <section> <title>1</title> </section> <section> <title>2</title> </section> <section> <title>3</title> <subsection> <title>3.1</title> </subsection> <subsection> <title>3.2</title> </subsection> </section> <section> <title>4</title> </section> <section> <title>5</title> <subsection> <title>5.1</title> </subsection> <subsection> <title>5.2</title> </subsection> </section> </session> Assuming my intention is use <title>,What I intend to generate is 1.html 2.html 3.1.html [pls note section 3.html is not generated because of //Section[not(SubSection)] ] 3.2.html 4.html 5.1 html [again 5.html will not be generated] 5.2.html Having mentioned this, I wish to ask another Q ? I think this I can get only using xsl grouping / xsl:key but understand xslt 2 has better option If I need to display an html output like 1.title [section title] ? will actually be linked to 1.html 2.title 3.title [ie section title appears only once before the start of 1st subsection title & no links as 3.html is not exist] 3.1 title [subsection title] ? will be linked to 3.1.html 3.2 title [subsection title] 4.title 5.title [section title] 5.1 title [subsection title] 5.2 title [subsection title] And so on? Thanks, karl ___________________________________________________________ All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine http://uk.docs.yahoo.com/nowyoucan.html
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] listing elements & sub-el, Karl | Thread | Re: [xsl] [XSLT2] Some common, gene, Christian Roth |
Re: [xsl] Re: building a hierarchic, Albert Juhé | Date | [xsl] Iteration without nodes, Frank Daly |
Month |