473,804 Members | 3,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4047
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:styleshe et 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:appl y-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="positio n()"
/></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|da ta">
<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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.microso ft.com/office/word/2003/wordml">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/">

<w:wordDocume nt
xmlns:w="http://schemas.microso ft.com/office/word/2003/wordml"
xmlns:v="urn:sc hemas-microsoft-com:vml"
xmlns:o="urn:sc hemas-microsoft-com:office:offi ce"
xml:space="pres erve">
<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="positio n()"
/></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|da ta">
<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:val ue-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
5469
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 as the original form in InfoPath. However, pictures which were included in an InfoPath form's RTF field before, are encoded in XHTML and embedded in the XML file as follows: <img style="WIDTH: 541px; HEIGHT: 330px" tabIndex="-1" height="330"...
6
3523
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 value="2">Yes</option> <option value="1">No</option> <option value="0">-</option>
1
1705
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 R12C6 R2C1 R234C2 R23C3 R3C1 R3C6 R4C1 R4C3 R4C5 R4C6 R5C1 R5C2 R5C3 R5C5 R56C6 R6C1 ...
0
1697
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 also generates xsl fo automatically Can any one suggest how to go about developing the stylesheet Regards Pooja :)
1
1270
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> <lname>Jones</lname> <active>1</active> <jobtitle>Sales Manager</jobtitle> <alternateRepNumbers>
0
1460
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 example, in a web page, a user clicks on a link or button, the XML data from an external file is inserted into a WordML document, and then is offered for download to the user. The reason why I am using WordML is because we have 20-30 word documents...
4
1805
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 http://rep.oio.dk/Microsoft.com/officeschemas/welcome.htm) to a reasonably clean (X)HTML format. (The reason being that, combined with some PHP scripting it should be possible to store the embedded images, which is pretty neat).
1
3160
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 (XmlDocument). The document is tagged in certain places so that the C# application can search for those tags (using the System.Xml namepace) and fill
1
1968
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
10578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10077
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9152
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.