Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 February 22nd, 2008, 12:11 PM
Authorized User
 
Join Date: May 2007
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"?>

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

And here is the stylesheet.
<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xforms="http://www.w3.org/2002/xforms/cr"
xmlns:xmml="http://www.xmml.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<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:model>
           <xforms:submission action="URL" method="post" />

          <xforms:instance xmlns="">

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

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

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

      </xforms:model>

    </head>
      <body>



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

      </body>
      </html>
      </xsl:template>


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

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

<xforms:bind>
<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>
</xsl:for-each>
</xforms:bind>
 </xsl:template>
  </xsl:stylesheet>


 
Old February 22nd, 2008, 12:24 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You have two templates which match on "data"

<xsl:template match="data" >

and

<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 -/
 
Old February 22nd, 2008, 12:33 PM
Authorized User
 
Join Date: May 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi. samjudson
thanks a lot. got it.






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





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