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 January 4th, 2007, 07:17 PM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default xml to html with xsl

I have the following XML code:

<p:tNumbers>
            <p:Number p:MType="Telephone" p:Usage="Business Line">
                <p:NumberElement p:ElementType="CountryCode">1</p:NumberElement>
             </p:Number>
</p:Numbers>

    <cb:Body>
            <cb:Students>
                <cb:residency label="west" unit="Pct">75</cb:residency>
                <cb:residency label="east" unit="Pct">25</cb:residency>
            </cb:Students>
    </cb:Body>
I get the actual node name - "tNumber" and "students" with "name()"

and I get actual children names by using "."
How can I use XSL to get the actual types...example - "Thelephone" or "CountryCode" or "west", "east" in the output.

Thanks.
 
Old January 4th, 2007, 08:14 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can access the value of an attribute node using an expression such as

<xsl:value-of select="@p:ElementType"/>

Make sure that (a) you are positioned on the right element as context node, and (b) that the namespace prefix p is declared in the stylesheet.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 4th, 2007, 08:31 PM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Is there an easier function that will access the value of every single attribute node in a tree?




Quote:
quote:Originally posted by mhkay
 You can access the value of an attribute node using an expression such as

<xsl:value-of select="@p:ElementType"/>

Make sure that (a) you are positioned on the right element as context node, and (b) that the namespace prefix p is declared in the stylesheet.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 5th, 2007, 04:48 AM
Registered User
 
Join Date: Jan 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use //@* to access every attribute in the document
e.g.
    <xsl:for-each select="//@*">
        <xsl:value-of select="name()" /> = <xsl:value-of select="." /> <br />
    </xsl:for-each>

 
Old January 5th, 2007, 05:30 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The expression //@* selects all the attribute nodes in a document.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML code from XML to display using XSL koenige XSLT 6 October 27th, 2008 08:11 AM
line number in xml using xsl and html link mrame XSLT 3 June 17th, 2008 01:36 PM
Rendering HTML inside XML through XSL - HELP !!! jilly XSLT 6 May 23rd, 2007 10:36 AM
XML/XSL to actual HTML tcstom XML 3 December 9th, 2005 01:36 PM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM





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