Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 4th, 2008, 09:57 AM
Authorized User
Join Date: May 2007
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default help on xslt transformation

Assuming we have an xml document like the one below.
   <node1 label="label1" type="integer" />
   <node2 label="label2" type="date" />
   <node3 label="label2" type="string" />
 we need to transform this doc into XForms doc.
The model part looks like this
………………………………………… ………………….
………………………………………… ………………….
<xforms:bind nodeset="node1" required="true()" type="xs:integer"/>
<xforms:bind nodeset="node2" required="true()" type="xs:date"/>
<xforms:bind nodeset="node3" required="false()" type="xs:string"/>

for each node in xml document xslt processor should generates an XForms control element <xforms:input ……….> with link to the corresponding bind node. The label of each XForms control should take its value from the attribute [label].
The expected result it should like this

<xforms:input ref="node1">
<xforms:label> label1 </xforms:label>
</xforms:input> </p>
<xforms:input ref="node2">
<xforms:label> label2 </xforms:label>
</xforms:input> </p>
<xforms:input ref="node3">
<xforms:label> label3 </xforms:label>
</xforms:input> </p>

The question is how to write a template that generates this part of XForms dynamically?

Any help is much appreciated

Old March 4th, 2008, 10:12 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts

Your samples are not complete so the following stylesheet is not complete either but it shows you how to use modes to process nodes twice:

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

  <xsl:template match="data">
        <xsl:apply-templates select="*" mode="binding"/>
        <xsl:apply-templates select="*" mode="controls"/>


  <xsl:template match="data/*" mode="binding">
    <xforms:bind nodeset="{local-name()}" required="true()" type="xs:{@type}"/>

  <xsl:template match="data/*" mode="controls">
      <xforms:input ref="{local-name()}">
        <xforms:label><xsl:value-of select="@label"/></xforms:label>

Old March 4th, 2008, 10:14 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

First, you seem to be posting multiple posts with almost identical subject lines - this is not good forum etiquette. Try to be a little bit more descriptive.

Secondly, its not clear from your post if this is one transformation (i.e. you want the input XML to be transformed twice in the same XSLT file) or if this is a two stage transformation.

It really sounds more like the former but from the previous posts you're written I'm suprised you can't work this out yourself.

<xsl:for-each select="/data/*">
<xforms:input ref="{local-name()}">
  <xforms:label><xsl:value-of select="@label"/></xforms:label>
If that isn't what you want then try showing us what you've tried so far and why it doesn't work.

/- Sam Judson : Wrox Technical Editor -/

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on XSLT transformation li72 XSLT 2 February 22nd, 2008 12:33 PM
help with xslt transformation li72 XSLT 6 November 19th, 2007 01:51 PM
XSLT transformation using JDK 1.5.0 kgoldvas XSLT 4 October 30th, 2007 02:06 PM
XSLT transformation yengzhai XSLT 1 April 21st, 2005 05:51 AM
XSLT transformation causes ^M reddygaru XSLT 2 December 16th, 2003 10:41 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.