Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 22nd, 2008, 12:11 PM
Authorized User
Join Date: May 2007
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help on XSLT transformation

Hi. Guys
I am trying to transform the below xml doc into XForms. The stylesheet contains of two templates. The first is to read the xml doc and copy the instance data. The second is to built up the binding part. Although the binding part is contrasted well (i.e. the instance data has successfully initiated), but it is not functioned as it suppose as to be. in addition, the UI is rendered just fine.
I diagnostic the problem as to do with copying the instance data, this is because if I eliminate the first template and place the instance data by hand, every thing is running just perfect.
Any clue?
Your help is much appreciated

Here is the xml doc.
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="bind.xsl"?>

    <node1 null="true" type="integer"> First Node </node1>
    <node2 null="true" type="date" > Second Node </node2>
    <node3 null="false" type="string" > Third Node </node3>

And here is the stylesheet.
<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns="http://www.w3.org/1999/xhtml"
<xsl:output method="xhtml" indent="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />

        <xsl:template match="/">

     <html >
        <head> <title>Title comes here </title>
           <xforms:submission action="URL" method="post" />

          <xforms:instance xmlns="">

       <xsl:apply-templates select="data" />

  <xsl:for-each select="data/*">
        <xsl:call-template name="templatename" />

  <xforms:bind nodeset="{local-name()}"
               type="{concat('xs:', @type)}"/>



          <xforms:input ref="node1" > <xforms:label> <xsl:value-of select="data/node1" /> </xforms:label> </xforms:input>
          <xforms:input ref="node2" > <xforms:label> <xsl:value-of select="data/node2" /> </xforms:label> </xforms:input>
          <xforms:input ref="node3" > <xforms:label> <xsl:value-of select="data/node3" /> </xforms:label> </xforms:input>
          <p> <xforms:submit> <xforms:label> Click here to submit </xforms:label> </xforms:submit> </p>


  <xsl:template match="data" >
    <xsl:copy-of select="data/*"/>

  <xsl:template match="data" name="templatename">

<xsl:for-each select="data/*">

<xsl:attribute name="nodeset"><xsl:value-of select="local-name()"/></xsl:attribute>
<xsl:attribute name="required"><xsl:value-of select="@null"/>()</xsl:attribute>
<xsl:attribute name="type">xs:<xsl:value-of select="@type"/></xsl:attribute>

Reply With Quote
  #2 (permalink)  
Old February 22nd, 2008, 12:24 PM
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

You have two templates which match on "data"

<xsl:template match="data" >


<xsl:template match="data" name="templatename">

It is not very well defined which of these will be called - it might be either, or an error might be raised depending on the XSLT processor used.

If you are using xsl:call-template, then you don't need to specify the "match" attribute. The following is fine:

<xsl:template name="templatename">

Also, inside the first xsl:template the xsl:copy-of instruction is equivalent to this:

<xsl:copy-of select="./data/*"/>

i.e. it tries to select all 'data' elements that are children of the current node, which is already a 'data' element, so is returning nothing. The following should work fine:

<xsl:copy-of select="*"/>

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #3 (permalink)  
Old February 22nd, 2008, 12:33 PM
Authorized User
Join Date: May 2007
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts

hi. samjudson
thanks a lot. got it.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
help on xslt transformation li72 XSLT 2 March 4th, 2008 10:14 AM
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

All times are GMT -4. The time now is 04:58 PM.

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