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 March 15th, 2007, 08:57 AM
Registered User
 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to uicdbd
Default template

I want to be able to start from the Listings/Listings element,
but no matter what I do I get all of the data (The PublishDate,DocumentationUrl,Disclaimer etc.)


Here is the XML File

<?xml version="1.0" encoding="utf-8"?>
<ListingDataFeed xmlns="http://platform.point2.com/schemas/2.0/listingDataFeed">
   <PublishDate>2007-03-02T14:25:35Z</PublishDate>
<DocumentationUrl>http://platform.point2.com/documentation</DocumentationUrl>

<Disclaimer>Information is deemed to be correct but not guaranteed.</Disclaimer>

<Copyright>Point2 Technologies, Inc.</Copyright>

   <Listings>
      <Listing>
         <ListingID>9011</ListingID>

         <PortalDomain>lonestar.point2agent.com</PortalDomain>

         <ListDate>2003-01-15T06:00:00Z</ListDate>

         <LastUpdateDate>2003-04-26T15:53:00Z</LastUpdateDate>

         <Status>For Sale</Status>

         <Title>Homes for Sale in Johnson County, Texas $35,000</Title>

</Listing>
   </Listings>
</ListingDataFeed>

===========
Here is the XSLT code I am using.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="text" encoding="utf-8" />


    <xsl:template match="/ListingDataFeed/Listings/Listings">


     <xsl:value-of select="ListingID" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="PortalDomain" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="RegionalMLSNumber/@publiclyVisible" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="RegionalMLSNumber" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="ListDate" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="SoldDate" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="LastUpdateDate" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="Status" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="Title" />
</xsl:template>
</xsl:stylesheet>




 
Old March 15th, 2007, 09:35 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XSLT starts with the root node "/" and if you haven't written a template rule for that node it uses a default one, which is to apply-templates to the children of that node. The same happens at each level: all the children are processed using the default template rules until it hits your explicit template rule. The default template rule for text nodes outputs the text, which is what you are seeing.

You can fix this a number of ways. You can add a root template that causes processing to start where you want it:

<xsl:template match="/">
  <xsl:apply-templates select="/ListingDataFeed/Listings/Listings"/>
</xsl:template>

or you can write a rule for text nodes that overrides the default one:

<xsl:template match="text()"/>

Incidentally your match pattern

   match="/ListingDataFeed/Listings/Listings">

should just be match="Listing". You only need to add information about the full path if you need to disambiguate the reference.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 15th, 2007, 10:31 AM
Registered User
 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to uicdbd
Default

Thanks Michael, but it is still not working.
If I use:
<xsl:template match="/">
  <xsl:apply-templates select="/ListingDataFeed/Listings/Listing"/>

     <xsl:value-of select="ListingID" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="PortalDomain" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="RegionalMLSNumber/@publiclyVisible" />
     <xsl:text>|</xsl:text>
     ....
</xsl:template>
</xsl:stylesheet>

I get ||||||||| - 51 times for each pipe in <xsl:text>|</xsl:text>,
but no data.

If I use:
<xsl:template match="/">
  <xsl:apply-templates select="/ListingDataFeed/Listings/Listing"/>
</xsl:template match="/"
.....
</xsl:stylesheet>
  I get - ERROR: Description: Keyword xsl:stylesheet may not contain xsl:value-of.

Not sure what to do. any help would be surely appreciated.

D.


 
Old March 15th, 2007, 10:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It might be a good idea to spend a few hours with a good book, it looks as if you're trying to do this by trial and error without understanding the concepts.

You want one template rule for "/":

<xsl:template match="/">
  <xsl:apply-templates select="/ListingDataFeed/Listings/Listing"/>
</xsl:template>

and one for Listing:

    <xsl:template match="Listing">
     <xsl:value-of select="ListingID" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="PortalDomain" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="RegionalMLSNumber/@publiclyVisible" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="RegionalMLSNumber" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="ListDate" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="SoldDate" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="LastUpdateDate" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="Status" />
     <xsl:text>|</xsl:text>
     <xsl:value-of select="Title" />
</xsl:template>

and template rules always go immediately inside an xsl:stylesheet element.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 15th, 2007, 12:28 PM
Registered User
 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to uicdbd
Default

Thank you again Michael. I added the above and reran.
Still no results. I believe that the problem lies in the XML file.
it has:
<?xml version="1.0" encoding="utf-8"?>
<ListingDataFeed xmlns="http://platform.point2.com/schemas/2.0/listingDataFeed">
   <PublishDate>2007-03-02T14:25:35Z</PublishDate>
   <DocumentationUrl>http://platform.point2.com/documentation</DocumentationUrl>
   <Disclaimer>Information is deemed to be correct.</Disclaimer>
   <Copyright>Point2 Technologies, Inc.</Copyright>

   <Listings>
      <Listing>
         <ListingID>9011</ListingID>
         ....
      </Listing>
   </Listings>
 </ListingDataFeed>

If I remove the xmlns="http://platform.point2.com/schemas/2.0/listingDataFeed"
from the <ListingDataFeed - it works ok. When left in it produces no results.

Would you please relpy on this.

Thanks for the book rec, I will comply.

D.



 
Old March 15th, 2007, 12:54 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please follow the link to "default namespace" in the first sticky post in this forum for advice on this common problem. Sorry that among all your other errors I didn't spot this one.

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
Recursive Template Help bucky483 XSLT 1 July 20th, 2007 12:21 PM
template uicdbd XSLT 1 March 14th, 2007 05:16 PM
calling one template in other template VijayKumar XSLT 3 September 15th, 2005 11:12 AM
Template - parameters narooma.12 BOOK: Professional Crystal Reports for VS.NET 0 August 27th, 2004 12:45 AM





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