[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Converting siblings into children
Subject: RE: [xsl] Converting siblings into children From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Fri, 4 Nov 2005 21:17:41 -0000 |
The problem is known as positional grouping. In XSLT 2.0 the solution is: <xsl:for-each-group group-starting-with="p[a]"> <p><xsl:copy-of select="a,subsequence(current-group(),2)"/></p> </xsl:for-each-group> It's a bit harder than that in 1.0, do a search for "XSLT positional grouping". Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Woods, Christopher [mailto:cwoods@xxxxxxxxxxxxxxxxx] > Sent: 04 November 2005 20:49 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Converting siblings into children > > I have a number of html files that I converted to xml using python. > Problem is that all the <p> tags are siblings. > > Given this: > > <?xml version="1.0"?> > <html> > <body> > <p><a name="one"><b>1.1.1</b></a></p> > <p>1.1.1.1 </p> > <p>1.1.1.2 </p> > <p>1.1.1.3 </p> > <p>1.1.1.4 </p> > <p><a name="two"><b>1.1.2</b></a></p> > <p>1.1.2.1 </p> > <p>1.1.2.2 </p> > <p>1.1.2.3 </p> > <p>1.1.2.4 </p> > <p>1.1.2.5 </p> > <p>1.1.2.6 </p> > <p>1.1.2.7 </p> > <p>1.1.2.8 </p> > <p><a name="three"><b>1.1.3</b></a></p> > <p>1.1.3.1 </p> > <p>1.1.3.2 </p> > <p>1.1.3.3 </p> > <p>1.1.3.4 </p> > <p>1.1.3.5 </p> > <p>1.1.3.6 </p> > </body> > </html> > > I need an output like this: > > <p> > <a name="one"><b>1.1.1</b></a> > <p>1.1.1.1 </p> > <p>1.1.1.2 </p> > <p>1.1.1.3 </p> > <p>1.1.1.4 </p> > </p> > > <p> > <a name="two"><b>1.1.2</b></a> > <p>1.1.2.1 </p> > <p>1.1.2.2 </p> > <p>1.1.2.3 </p> > <p>1.1.2.4 </p> > <p>1.1.2.5 </p> > <p>1.1.2.6 </p> > <p>1.1.2.7 </p> > <p>1.1.2.8 </p> > </p> > > <p> > <a name="three"><b>1.1.3</b></a> > <p>1.1.3.1 </p> > <p>1.1.3.2 </p> > <p>1.1.3.3 </p> > <p>1.1.3.4 </p> > <p>1.1.3.5 </p> > <p>1.1.3.6 </p> > </p> > > Any ideas? Thanks in advance.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Converting siblings into chil, Woods, Christopher | Thread | [xsl] XML 2005: Call for Posters, Kate Hamilton |
Re: [xsl] Matching certain elements, Wendell Piez | Date | Re: [xsl] Recursive substitution, David Carlisle |
Month |