Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
<data>
   <node1 label="label1" type="integer" />
   <node2 label="label2" type="date" />
   <node3 label="label2" type="string" />
   </data>
 we need to transform this doc into XForms doc.
The model part looks like this
<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>

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

<p>
<xforms:input ref="node1">
<xforms:label> label1 </xforms:label>
</xforms:input> </p>
<p>
<xforms:input ref="node2">
<xforms:label> label2 </xforms:label>
</xforms:input> </p>
<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


Reply With Quote
  #2 (permalink)  
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
Default

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:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xforms="http://www.w3.org/2002/xforms">

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

  <xsl:template match="data">
    <html>
      <head>
        <title>Example</title>
        <xsl:apply-templates select="*" mode="binding"/>
      </head>
      <body>
        <xsl:apply-templates select="*" mode="controls"/>

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

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

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

</xsl:stylesheet>
Reply With Quote
  #3 (permalink)  
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
Default

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.

Code:
<xsl:for-each select="/data/*">
<p>
<xforms:input ref="{local-name()}">
  <xforms:label><xsl:value-of select="@label"/></xforms:label>
</xforms:input>
</p>
</xsl:for-each>
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 -/
Reply With Quote
Reply


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 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



All times are GMT -4. The time now is 09:15 PM.


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