Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: xsl - extracting corresponding pairs from different roots

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 11/4/2005 1:44:00 PM

Rob Smegma wrote:


> <root>
> <head>
> <meta name=1/>

Should be
   <meta name="1" />
then to be well-formed, attribute values need to be quoted.
Same below for the other meta elements.

> <meta name=2/>
> <meta name=3/>
> </head>
> <body>
> <msg>HEY</msg>
> <msg>YOU</msg>
> <msg>THERE</msg>
> </body>
> </root>
> 
> I would like to transform this into:
> 
> (1,HEY), (2,YOU), (3,THERE)
> 
> The meta elements correspond to the msg elements.

Process the meta elements and then use the position (or perhaps the name 
attribute, not clear from your description what establishes the 
relationship) to find the corresponing msg element.
As you seem to want to have text output then use xsl:output method text.
Here is an example stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

<xsl:output method="text" media-type="text/plain" encoding="UTF-8" />

<xsl:variable name="messages" select="/root/body/msg" />

<xsl:template match="root">
   <xsl:apply-templates select="head/meta" />
</xsl:template>

<xsl:template match="meta">
   <xsl:variable name="index" select="position()" />
   <xsl:text>(</xsl:text>
   <xsl:value-of select="concat(@name, ',', $messages[$index])" />
   <xsl:text>)</xsl:text>
   <xsl:if test="position() != last()">
     <xsl:text>, </xsl:text>
   </xsl:if>
</xsl:template>

</xsl:stylesheet>


-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent