G
Gary Huntress
Hi,
I'm having trouble with an xslt transform. I'm trying to transform a
vector into an array of width N. For example here is my vector:
<data>
<x id="1">1.2</x>
<x id="2">.2</x>
<x id="3">.87</x>
<x id="4">.333</x>
<x id="5">.4442</x>
<x id="6">1.1</x>
<x id="7">.8</x>
<x id="8">.6543</x>
<x id="9">.8761</x>
<x id="10">1</x>
<x id="11">.99</x>
<x id="12">.2</x>
</data>
and given N=4 I want to transform it to
<array>
<row id="1">
<x id="1">1.2</x>
<x id="2">.2</x>
<x id="3">.87</x>
<x id="4">.333</x>
</row>
<row id="2">
<x id="1">.4442</x>
<x id="2">1.1</x>
<x id="3">.8</x>
<x id="4">.6543</x>
</row>
<row id="3">
<x id="1">.8761</x>
<x id="2">1</x>
<x id="3">.99</x>
<x id="4">.2</x>
</row>
</array>
I can successfully use @id mod $N to identify each <row> but I have
not found a way to properly create the output. Here is a failed
attempt:
<xsl:template match="x">
<xsl:choose>
<xsl:when test="(@id mod 4)=1">
<row>
<x><xsl:value-of select="."/></x>
</row>
</xsl:when>
<xsltherwise>
<x><xsl:value-of select="."/></x>
</xsltherwise>
</xsl:choose>
</xsl:template>
The "otherwise" <x> elements are not properly nested in the <row> and
I don't know how to make them children of the newly created <row>.
Should I be using an axis here? Or am I missing an obvious solution?
Thx,
Gary H.
I'm having trouble with an xslt transform. I'm trying to transform a
vector into an array of width N. For example here is my vector:
<data>
<x id="1">1.2</x>
<x id="2">.2</x>
<x id="3">.87</x>
<x id="4">.333</x>
<x id="5">.4442</x>
<x id="6">1.1</x>
<x id="7">.8</x>
<x id="8">.6543</x>
<x id="9">.8761</x>
<x id="10">1</x>
<x id="11">.99</x>
<x id="12">.2</x>
</data>
and given N=4 I want to transform it to
<array>
<row id="1">
<x id="1">1.2</x>
<x id="2">.2</x>
<x id="3">.87</x>
<x id="4">.333</x>
</row>
<row id="2">
<x id="1">.4442</x>
<x id="2">1.1</x>
<x id="3">.8</x>
<x id="4">.6543</x>
</row>
<row id="3">
<x id="1">.8761</x>
<x id="2">1</x>
<x id="3">.99</x>
<x id="4">.2</x>
</row>
</array>
I can successfully use @id mod $N to identify each <row> but I have
not found a way to properly create the output. Here is a failed
attempt:
<xsl:template match="x">
<xsl:choose>
<xsl:when test="(@id mod 4)=1">
<row>
<x><xsl:value-of select="."/></x>
</row>
</xsl:when>
<xsltherwise>
<x><xsl:value-of select="."/></x>
</xsltherwise>
</xsl:choose>
</xsl:template>
The "otherwise" <x> elements are not properly nested in the <row> and
I don't know how to make them children of the newly created <row>.
Should I be using an axis here? Or am I missing an obvious solution?
Thx,
Gary H.