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/