xsl-list
[Top] [All Lists]

Re: [xsl] Wrapping two different elements in parent element.

2007-09-28 04:19:18
Hi Bruno,

That is very easy with XSLT 2.0:

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:output indent="yes"/>
 <xsl:template match="something">
  <something-else>
   <usg>
    <xsl:for-each-group select="*" group-ending-with="word_form">
     <form><xsl:apply-templates select="current-group()"/></form>
    </xsl:for-each-group>
   </usg>
  </something-else>
 </xsl:template>

 <xsl:template match="word_case">
  <case><xsl:value-of select="."/></case>
 </xsl:template>

 <xsl:template match="word_form">
  <form><xsl:value-of select="."/></form>
 </xsl:template>
</xsl:stylesheet>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina - http://aboutxml.blogspot.com/
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


Bruno Nahod wrote:
Hello,

I’m working on transforming xml export from a dictionary application; witch is unbelievably unstructured into a well formed xml document (based on TEI recommendations). My biggest problem is how to wrap two (or more) elements into parent element. This is the simplified example of what I have and what I’m hoping to get;

This I have (export)

<?xml version="1.0" encoding="UTF-8"?>

<something>

<word_case>N</word_case>

<word_form>some_word_N</word_form>

<word>G</word_case>

<word>some_word_G</word_form>

<word_case>D</word_case>

<word>some_word_D</word_form>

</something>

This I hope to get;

<?xml version="1.0" encoding="UTF-8"?>

<something_else>

<usg>

<form>

<case>N</case>

<orth>some_word_N</orth>

</form>

<form>

<case>G</case>

<orth>some_word_G</orth>

</form>

<form>

<case>D</case>

<orth>some_word_D</orth>

</form>

</usg>

</something_else>

Thank you very much

Bruno.


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