xsl-list
[Top] [All Lists]

RE: [xsl] Help on XSL to tranform simple flat xml sequentially

2009-08-30 12:13:50
In XSLT 2.0 you can do

<xsl:for-each-group select="*" group-starting-with="para[(_at_)role='title']">
  <paragraph>
    <xsl:apply-templates select="current-group()"/>
  </paragraph> 
</xsl:for-each-group>

In 1.0 it's rather harder - google for "XSLT positional grouping".

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 
 

-----Original Message-----
From: Christian Oshiro [mailto:chris_oshiro(_at_)yahoo(_dot_)com] 
Sent: 30 August 2009 17:08
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Help on XSL to tranform simple flat xml sequentially

This seems like a pretty simple thing to do, but I usually 
rely on nested xml. How can I tranform xml that looks like this:

<para role=title>main title1</para>
<para role=subtitle>subtitle1</para>
<para>This is the body of the paragraph. 1</para> <list>some 
stuff 1</list> <para role=title>main title2</para> <para 
role=subtitle>subtitle2</para> <para>This is the body of the 
paragraph. 2</para> <list>some stuff 2</list> <para 
role=title>main title3</para> <para 
role=subtitle>subtitle3</para> <para>This is the body of the 
paragraph. 3</para> <list>some stuff 3</list>

I'd like to transform this using xlst to something like this:

<paragraph>
  <title>main title1</title>

<subtitle>subtitle1</subtitle>

<body>This is the body of the paragraph. 1</body>

<list>some stuff 1</list>
</paragraph>
<paragraph>
  <title>main title2</title>
  <subtitle>subtitle2</subtitle>
  <body>This is the body of the paragraph. 2</body>
  <list>some stuff 2</list>
</paragraph>
<paragraph>
  <title>main title3</title>
  <subtitle>subtitle3</subtitle>
  <body>This is the body of the paragraph. 3</body>
  <list>some stuff 3</list>
</paragraph>

So i need to go node by node and test when role=title shows 
up. Thanks for the insight.


      

--~------------------------------------------------------------------
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>