xslt wordml create table

U

utterberg

If I have an xml that looks something like this:

<section>
<item>
<label>label one</label>
<data>123</label>
</item>
<item>
<label>label two</label>
<data>456</label>
</item>
<item>
<label>label three</label>
<data>789</label>
</item>

... and so on...

</section>

Then I would like to have a table that looks like this:
label one 123 label two 456
label three 789 label four 908
....and so on

How do I solve this? If it were html I would do like this:
<template match="/">
<table border="1">
<xsl:apply-templates select="section/item" />
</table>
</template>

<xsl:template match="item">
<xsl:if test="(position() mod 2) = 1">
<xsl:text disable-output-escaping="yes">&lt;tr&gt;</xsl:text>
</xsl:if>

<td>
<xsl:value-of select="label"/>
</td>
<td>
<xsl:value-of select="data"/>
</td>

<xsl:if test="(position() mod 2) = 0">
<xsl:text disable-output-escaping="yes">&lt;/tr&gt;</xsl:text>
</xsl:if>
</xsl:template>

But since I'm now working with wordml the "&lt;" and "&gt;" doesn't
work. Any ideas how to manage this in wordml?

Thanks in advance!
..christer
 
?

=?ISO-8859-1?Q?Joachim_Wei=DF?=

If I have an xml that looks something like this: ....
<xsl:text disable-output-escaping="yes">&lt;tr&gt;</xsl:text>
don't try to put out tags like this ...

how about this ...

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<head>
<title></title>
</head>
<body><xsl:apply-templates /></body>
</html>
</xsl:template>
<xsl:template match="section">
<xsl:element name="table">
<xsl:apply-templates select="item[(position() mod 2)=1]"/>
</xsl:element>
</xsl:template>

<xsl:template match="item[(position() mod 2)=1]">
<xsl:variable name="pos"><xsl:value-of select="position()"
/></xsl:variable>
<tr>
<xsl:apply-templates />
<xsl:apply-templates select="../item[$pos+1]"/>
</tr>

</xsl:template>

<xsl:template match="item">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="label|data">
<xsl:element name="td">
<xsl:value-of select="." />
</xsl:element>
</xsl:template>
</xsl:stylesheet>


Sincerly Jo
 
U

utterberg

Thanks for your help Joachim! It almost works... The one row that I
can't get to work is:
<xsl:apply-templates select="../item[$pos+1]"/>

It creates an error. (doesn't say what, just that it's not working)

Here's the code I'm working with.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">

<xsl:eek:utput method="xml" indent="yes" />

<xsl:template match="/">

<w:wordDocument
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice"
xml:space="preserve">
<w:docPr />


<w:body>
<xsl:apply-templates select="section" />
</w:body>
</w:wordDocument>
</xsl:template>

<xsl:template match="section">
<xsl:element name="w:tbl">
<xsl:apply-templates select="item[(position() mod
2)=1]"/>
</xsl:element>
</xsl:template>


<xsl:template match="item[(position() mod 2)=1]">
<xsl:variable name="pos"><xsl:value-of select="position()"
/></xsl:variable>
<w:tr>
<xsl:apply-templates />
<xsl:apply-templates select="../item[$pos+1]"/>
</w:tr>


</xsl:template>


<xsl:template match="item">
<xsl:apply-templates />
</xsl:template>


<xsl:template match="label|data">
<w:tc>
<w:tcPr>
<w:tcW w:w="3240" w:type="dxa"/>
</w:tcPr>
<w:p>
<w:pPr>
<w:spacing w:before="60"/>
</w:pPr>
<w:r>
<w:rPr>
<w:sz w:val="20"/>
<w:sz-cs w:val="20"/>
<w:lang w:val="SV"/>
</w:rPr>
<w:t><xsl:value-of select="." /></w:t>
</w:r>
</w:p>
</w:tc>
</xsl:template>
</xsl:stylesheet>

Do you have any other suggestions?

Thanks!
..christer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top