Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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, 2006, 02:21 PM
Registered User
 
Join Date: Feb 2006
Location: Colorado Springs, CO, .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default total noob xslt question

I'm sure this is a no brainer but my head hurts trying to figure this out... so please help.

I have xml like the following

<?xml version="1.0">
<doc xmlns:abc="ab:cd:ef:gh">
<title abc:font="Times New Roman">My Father Was A Monkey</title>
</doc>

I want to write some xslt to grab both the font attribute and the title value.

How the heck do I do this? I'm not used to writing xslt for xml that has namespaces declared (flame on), so I don't get how to reference the attribute here... Please help!

 
Old February 22nd, 2006, 02:28 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Add this to your xsl:stylesheet element:
Code:
xmlns:abc="ab:cd:ef:gh"
Then use something like:
Code:
<xsl:value-of select="/doc/title/abc:font"/>
in the sheet. The elements aren't in the "ab:cd:ef:gh" namespace so you can select these using XPath without prefixes.

I suggest this FAQ as a guide on namespace questions:

http://www.dpawson.co.uk/xsl/sect2/N5536.html

--

Joe (Microsoft MVP - XML)
 
Old February 22nd, 2006, 03:35 PM
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
Default

<xsl:template match="doc" xmlns:abc="ab:cd:ef:gh">
  font: <xsl:value-of select="title/@abc:font"/>
  title: <xsl:value-of select="title"/>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 22nd, 2006, 04:35 PM
Registered User
 
Join Date: Feb 2006
Location: Colorado Springs, CO, .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you both.




Similar Threads
Thread Thread Starter Forum Replies Last Post
noob question mattl Java Basics 1 August 27th, 2007 11:28 PM
Simple (noob) Question Bourne C++ Programming 6 March 6th, 2007 10:07 AM
Noob question to use links with xml ... antchan99 XML 0 May 18th, 2006 05:22 AM
Noob XML question Skido XML 0 December 23rd, 2005 04:25 PM
Noob Question jverdin BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 3 April 2nd, 2004 10:01 AM





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