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 21st, 2008, 08:07 AM
Authorized User
 
Join Date: May 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to achieve dynamic binding

Assuming we have an xml document like the one below.
<data>
   <node1 null="true" type="integer" />
   <node2 null="true" type="date" />
   <node3 null="false" type="string" />
   </data>
 we need to transform this doc into XForms doc. The behaviour task in XForms is placed inside <model> </model> node.
If we write this part by hand, it looks like
<model>
<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"/>
</model>
But I need to call a template which builds up this part dynamically. i.e. Xslt processor will visit each node in xml document, read its name as well as its attributes values (null, type), then construct the desired <model> node.

The main structure of this template could be like this
<xsl:template match="data">
  <xsl:for-each select="data/*">
    <xsl:value-of select="local-name()"/>
    <xsl:value-of select="@null" />
    <xsl:value-of select="@type" />

   </xsl:for-each>
  </xsl:template>
My question is how to build up a generic statement that generates the binding part?

Any help is much appreciated


 
Old February 21st, 2008, 08:13 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Use the xsl:attribute instruction, something like the following:

<xforms:bind>
<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>
</xforms:bind>


/- Sam Judson : Wrox Technical Editor -/
 
Old February 21st, 2008, 10:26 AM
Authorized User
 
Join Date: May 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi.Samjudson
Thanks a lot for ur help
Actually I created the template below and it was called as <xsl:call-template name="templatename" />
The outcome of the translations was :
<xforms:bind nodeset="node3" required="false()" type="xs:string"/> which means we got only the last node produced by the template and we missed the first and second ones.

Any clue?
Many thanks in advance

Here is the 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>


 
Old February 21st, 2008, 11:46 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

You want one xforms:bind element for each child of the data element so you need to move the xforms:bind element inside of the for-each e.g.
Code:
<xsl:for-each select="data/*">
  <xforms:bind nodeset="{local-name()}"
               required="{@null}"
               type="{concat('xs:', @type)}"/>
</xsl:for-each>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Binding in Report Viewer ritesh2381 ASP.NET 2.0 Professional 0 November 19th, 2007 07:29 AM
VB6 ADO Dynamic Data Binding Question pad Pro VB Databases 1 January 28th, 2005 10:43 PM
Crystal Reports Dynamic binding field objects velkropie Crystal Reports 0 December 1st, 2004 12:21 AM
Crystal Reports Dynamic binding field objects velkropie BOOK: Professional Crystal Reports for VS.NET 0 November 30th, 2004 11:35 PM





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