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 | 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 November 3rd, 2005, 08:11 AM
Registered User
Join Date: Nov 2005
Location: trichy, , India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Copying Source Node attributes to output node


I am trying to apply an XSLT stylesheet to convert a source XML Doc into a HTML Checkbox TAG. The source XML can have a number of attributes. Hence i want to loop thry the sourcenode's attributes and add it to the output HTML <INPUT> TAG's attributes.
The source XML
<?xml version="1.0" encoding="iso-8859-1"?>
<ww:checkbox name='' value='' required='no' selected='no' message='the field is not selected'/>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ww='http://www.fitpro.com'>
<xsl:output method="html"/>
 <xsl:template match="/">
<xsl:template match="ww:checkbox">
    <xsl:element name="input">
        <xsl:attribute name='type'>checkbox</xsl:attribute>
        <xsl:attribute name='name'>
            <xsl:value-of select="@name"/>
        <xsl:attribute name='value'>
            <xsl:value-of select="@value"/>
        <xsl:for-each select="attribute::*">
            <xsl:attribute name="name(.)"><xsl:value-of select="."/></xsl:attribute>

=<input xmlns:ww="http://www.fitpro.com" type="checkbox" name="checkbox1" value="agree"> But i want all the other attributes sych as required, selected, message etc to appear in the output. Is that possible?
Reply With Quote
  #2 (permalink)  
Old November 3rd, 2005, 08:46 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

I corrected two errors:

(a) added a namespace declaration in the source XML

(b) changed <xsl:attribute name="name(.)"> to <xsl:attribute name="{name(.)}">

and it gave the required output. Without the curly braces the attribute has an invalid name, and the XSLT 1.0 spec allows silent recovery from that error by simply ignoring the attribute. I expect that's what happened to you.

However you can achieve the result more easily by writing the template body as:

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

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old November 3rd, 2005, 09:46 AM
Registered User
Join Date: Nov 2005
Location: trichy, , India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks for that. I was seeing this curly brackets in some samepl code but did not figure out its importance. That was very very helpful. I am trying to develop an XML/XSLT driven Presentation layer framework components in CFC for some CFMX based applications and integrate it into a fusebox framework. My next step is to go a grab a copy of your XSLT and XPath Books..

Many thanks
Sathish Kumar

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
changing output for one node in XSLT shane_carty XSLT 3 February 27th, 2008 05:28 AM
How to delete a xml node with all attributes and s vishnu108mishra XML 2 November 14th, 2007 04:19 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
Use of Attributes prop.ty for a OOXML node Gianni Giaccaglini Excel VBA 1 September 24th, 2007 05:05 AM
Child Node Output Neal XSLT 0 June 7th, 2006 03:14 AM

All times are GMT -4. The time now is 11:50 PM.

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