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 September 18th, 2008, 08:04 AM
Registered User
 
Join Date: Sep 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL file can't find elements in XML data?

Hi all,

I've been working on a project to display a list of names and contact information based on an XML file generated through a web service. But I can't for the life of me read data using my XSL file, even though it looks to be dead on based on the web examples I've been using.

Here's the XML:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<Data xmlns="http://www.domain.com/schema/data" xmlns:dmd="http://www.domain.com/schema/data-metadata" dmd:date="2008-09-17">
    <Record userId="56103" username="smithj" dmd:sId="17777">
        <dmd:IndexEntry indexKey="DEPARTMENT" entryKey="Management" text="Management"/>
        <dmd:IndexEntry indexKey="COLLEGE" entryKey="Business" text="Business"/>
        <INFORMATION id="334635008" dmd:lastModified="2008-07-19T16:26:50">
            <DPHONE1/>
            <FAX1/>
            <WEBSITE>http://</WEBSITE>
            <PREFIX/>
            <FNAME>Joe</FNAME>
            <PFNAME/>
            <LNAME>Smith</LNAME>
            <EMAIL>[email protected]</EMAIL>
        </INFORMATION>
    </Record>
</Data>
And here's the XSL file:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">

<html>
<head>
<title>My Title</title>
</head>
<body>

<p>Text in body tag...</p>

<xsl:for-each select="Data/Record/INFORMATION">
   <p><b>Test: <xsl:value-of select="FNAME"/></b></p>
</xsl:for-each>

<p>Text in body tag...</p>

</body>
</html>

</xsl:template>
</xsl:stylesheet>
I'm using PHP's XSLTProcessor() to handle the actual transform and using XAMPP (Apache, PHP, etc) as my server. Based on what I'm seeing, the stuff above should show "Joe" in the browser. But I can't get anything to show at all from inside the for-each loop block. Am I doing something wrong?

Any help would be appreciated.

Thanks,
- Matt

 
Old September 18th, 2008, 09:02 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

See here for some good stuff on namespaces:

http://www.dpawson.co.uk/xsl/sect2/N...tml#d7563e1012

Your elements are in a namespace

xmlns="http://www.domain.com/schema/data"

but your path expression is trying to select elements in no namespace.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old September 18th, 2008, 09:37 AM
Registered User
 
Join Date: Sep 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks! That helped tremendously. I'm still relatively new to XSLT and hadn't run into namespaces before when just parsing RSS feeds.

Here's a link that helped put it all into place as the format corresponded most closely to what I was working with.

http://docs.codehaus.org/display/MIL...slt-namespaces

- Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
distinct data from XML using XSL Hughesie78 XSLT 5 November 20th, 2007 10:25 AM
Create XML file - add elements according to range remya1000 XML 5 October 3rd, 2007 02:50 PM
Adding elements from an XML to XSL. AjayLuthria XSLT 1 May 1st, 2007 12:12 PM
getting data from XML rendering with XSL louismanukonda XSLT 1 January 4th, 2006 10:37 AM
How to replace elements(from existed XML file)? hbcontract XML 1 October 30th, 2003 05:49 AM





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