xsl-list
[Top] [All Lists]

RE: Converting siblings into children

2005-11-04 14:17:41
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(_at_)EO(_dot_)Kollmorgen(_dot_)com] 
Sent: 04 November 2005 20:49
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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.



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>