newbie xpath - select certain siblings

I

iliad

Hi!

I would like to generate something like this:
....
<P>textbefore</P>
<P>
<UL>
<LI>point1</LI>
<LI>point2</LI>
</UL>
</P>
<P>textafter</P>

with this XML:
....
<item name = 'rtf_Body'>
<richtext>

<pardef id='3'>
<par def='3'>
textbefore
</par>

<pardef id='4' list='bullet'/>
<par def='4'>
point1
</par>
<par>
point2
</par>

<pardef id='5'>
<par def='5'>
textafter
</par>

</richtext>
</item>
....
 
J

Joris Gillis

Hi,
Tempore 10:33:50 said:
I would like to generate something like this:
...
<P>textbefore</P>
<P>
<UL>
<LI>point1</LI>
<LI>point2</LI>
</UL>
</P>
<P>textafter</P>

with this XML:
...
<item name = 'rtf_Body'>
<richtext>

<pardef id='3'>
<par def='3'>
textbefore
</par>

<pardef id='4' list='bullet'/>
<par def='4'>
point1
</par>
<par>
point2
</par>

<pardef id='5'>
<par def='5'>
textafter
</par>

</richtext>
</item>
...
This is certainly possible (in theory), but you're XML is not well-formed. And it happens to be mall-formed in a way it is unpossible to guess a correction.

is the structure:

<pardef id='3'>
<par def='3'>
textbefore
</par>
</pardef>

or

<pardef id='3'/>
<par def='3'>
textbefore
</par>

?

these structures would require completely different algorithms to produce the desired result.

regards,
 
I

iliad

joris, hi again!

you're right, it's a typo...
the correct xml is:

....
<item name = 'rtf_Body'>
<richtext>

<pardef id='3'/>
<par def='3'>
textbefore
</par>

<pardef id='4' list='bullet'/>
<par def='4'>
point1
</par>
<par>
point2
</par>

<pardef id='5'/>
<par def='5'>
textafter
</par>

</richtext>
</item>
 
J

Joris Gillis

Tempore 13:07:16 said:
you're right, it's a typo...

Then this might be a solution:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="xml" indent="yes"/>

<xsl:key name="par" match="par" use="generate-id(preceding::pardef[1])"/>

<xsl:template match="par"/>

<xsl:template match="pardef">
<xsl:apply-templates select="key('par',generate-id())" mode="makeP"/>
</xsl:template>

<xsl:template match="pardef[@list]">
<P>
<ul>
<xsl:apply-templates
select="key('par',generate-id())" mode="makeli"/>
</ul>
</P>
</xsl:template>

<xsl:template match="par" mode="makeP">
<P><xsl:apply-templates /></P>
</xsl:template>

<xsl:template match="par" mode="makeli">
<li><xsl:apply-templates /></li>
</xsl:template>

</xsl:stylesheet>



regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,000
Messages
2,570,252
Members
46,848
Latest member
CristineKo

Latest Threads

Top