473,408 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

xslt wordml create table

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

Oct 27 '05 #1
3 4014
ut*******@gmail.com schrieb:
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
Oct 27 '05 #2
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:output 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:o="urn:schemas-microsoft-com:office:office"
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

Oct 27 '05 #3
Nevermind. Solved it.

Thanks!

Oct 27 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sven Steinacker | last post by:
Hi, XSLT files generated by Microsoft InfoPath applied to an applicable XML file produces quite decent HTML presentations. At least with Mozilla and, of course, IE 6.0 the results look the same...
6
by: utterberg | last post by:
Hi, I've got an xml that looks like this: <section name="Risk"> <label>RISK MANAGEMENT (RM)</label> <field name="RM.1"> <ref>RM.1</ref> <label>Text goes here...</label> <option...
1
by: Ruby Tuesdays | last post by:
I have the following table with merge rows as follows: IDNUM IMAGE DESC CODENUM RATING NOTES ---------+-------+-------+------------+---------+--------- R1C1 R1C2 R1C3 R12345C4 R123C5 ...
0
by: poojasharma | last post by:
Hii Guys I have created word document on to which xml schema is mapped to create place holders for xml elements.Now i need to develop a xslt which generates a pdf for the wordml document and...
1
by: Thom Anderson | last post by:
Hi, I'm a newbee at XML so I need to ask this. I have an xml data like follows. <?xml version="1.0" encoding="utf-8" ?> <salesRep repnum="123" orgdate="16"> <fname>Joe</fname>...
0
by: JD | last post by:
Hello: I am trying to put together a solution that would programmatically insert XML data into a WordML document. I am trying to do this through a web page when a user clicks on a link. For...
4
by: dwergkees | last post by:
Hi, Got a litte problem here. I'm trying to create a XSLT file that will do a transformation from WordML format (MS Word XML format, see...
1
by: Pedro Rosas Silva | last post by:
Hi everyone, Is anybody aware of a way how to insert an image in a WordML document programmatically, through C#? I have a C# application that loads into memory a WordML document...
1
by: bklihjt | last post by:
Hi Can anyone guide me abut WordML...I need to create an XML file using wordML....pls provide samples...its urgent
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.