OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] Generating implicit wrapper element

[ Lists Home | Date Index | Thread Index ]

As Juliane says (hello Juliane), the xsl-list is a better place for this
kind of question.

Google for "XSLT positional grouping" to find examples of how to solve this
problem.

You need to understand that XSLT is writing a tree, it's not writing begin
and end tags. <ul></ul> is one instruction that writes one element node to
the result tree, it's not two instructions that write two tags. You can't
split it up: that would involve writing half a node to the result tree.

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

> -----Original Message-----
> From: Ferdinand Soethe [mailto:xml-dev@soethe.net] 
> Sent: 30 August 2005 13:56
> To: xml-dev@lists.xml.org
> Subject: [xml-dev] Generating implicit wrapper element
> 
> 
> I have an XML-document with paragraphs and list items that have no
> wrapper element around each list.
> 
> Something like this:
> 
> <par>my first para</par>
> <par>second para</par>
> <li>first list item of first list</li>
> <li>second list item of first list</li>
> <li>third list item of first list</li>
> <par>third para</par>
> <li>first list item of second list</li>
> <par>fourth para</par>
> <li>first list item of third list</li>
> <li>second list item of third list</li>
> 
> In my transformation I would like to add these implicit wrapper
> element around each of the list to get something like
> 
> <p>my first para</p>
> <p>second para</p>
> <ul>
> <li>first list item of first list</li>
> <li>second list item of first list</li>
> <li>third list item of first list</li>
> </ul>
> <p>third para</p>
> <ul>
> <li>first list item of second list</li>
> </ul>
> <p>fourth para</p>
> <ul>
> <li>first list item of third list</li>
> <li>second list item of third list</li>
> </ul>
> 
> My attempt to solve this with
> 
> <xsl:template match="Aufzaehlungspunkt">
>     
>   <xsl:if test="not(preceding-sibling::li)">
>     <ul>
>   </xsl:if>
>   
>   <li><xsl:apply-templates/></li>
> 
>   <xsl:if test="not(following-sibling::li)">
>     </ul>
>   </xsl:if>
> 
> </xsl:template>
> 
> ran into two separate problems:
> 
> 1. I'm not allowed to use <ul> without the matching </ul> (even though
>    that is in a separate if-branch below.
> 
> 2. The preceding-sibling and following-sibling-axes are only true when
>    dealing with the very first and the very last <li> in the document.
>    So rather than meaning 'previous element is not <li>' the meaning
>    'there is no more previous <li>-element in this document'.
> 
> Any ideas how to solve these problems with XML?
> 
> Oh, btw. I saw the solution suggested some years ago
> 
> <officers>
> <xsl:for-each select='/doc/person[@er="officer"]'>
> <person><xsl:value-of select='.'/></person>
> </xsl:for-each>
> </officers>
> 
> <xsl:for-each select='/doc/person[not(@er="officer")]'>
> <person><xsl:value-of select='.'/></person>
> </xsl:for-each>
> 
> </perslist>
>  </xsl:template>
> 
>  but this doesn't seem to be an option since I'm not using the
>  procedural style of processing my document.
> 
>  Thanks for any input,
> 
>  --
>  Ferdinand
> 
> --
> Ferdinand Soethe
> 
> 
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://www.oasis-open.org/mlmanage/index.php>
> 
> 






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS