 |
| 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
|
|
|
|

February 27th, 2009, 04:56 AM
|
|
Authorized User
|
|
Join Date: Feb 2009
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Accessing RSS Link Data
Hello...
I recently received a reply for how to access an RSS feed using the document() function like so:
<xsl:apply-templates select="document(concat('https:///www.test.com/rss?', $var))" mode="rss"/>
What I'd like to do now is access the /rss/channel/item/link node that's returned, follow that link and get a specific node's data. For example, if I accessed the above URI with the variable 'dogs' it would provide some information and a link to another document for more info (RESTful...) That link is a URI to yet another tree that contains a node named 'breed" for which I need to extract the data.
Thanks
Rob
|
|

February 27th, 2009, 05:22 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
The document() function returns a document node, you can put this in a variable and then navigate from it. For example
<xsl:variable name="doc" select="document(.....)"/>
<xsl:value-of select="$doc/rss/channel/item/link"/>
You're asking questions that suggest you haven't really learnt the fundamental concepts of the language. Could I suggest you do some background reading?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
The Following User Says Thank You to mhkay For This Useful Post:
|
|
|

February 27th, 2009, 06:24 AM
|
|
Authorized User
|
|
Join Date: Feb 2009
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Thanks for the answer. I appreciate it. I have bought your book (XSLT 2.0 and XPath 2.0 Programmer's Reference) but couldn't find what I was looking for. I do realize that it is a reference book vs a tutorial. Can you recommend a tutorial (book, web site, etc...) that I might find helpful? Thanks.
Rob
|
|

February 27th, 2009, 06:33 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
For a more gentle introduction to XSLT 2.0, that doesn't go quite so deep as mine, you might find Jeni Tennison's book to your taste. She explains things well and has a knack of making things simple without over-simplifying.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
The Following User Says Thank You to mhkay For This Useful Post:
|
|
|

March 5th, 2009, 07:57 AM
|
|
Authorized User
|
|
Join Date: Feb 2009
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Hi again...
Time for part 2 of this question. I've searched and searched and can't find the answer for this: In the example above you gave me good information on how to get to /rss/channel/item/link. Now what I need to do is get the data from a given node in the document that is accessed by the link URL. I've tried the following:
<xsl:variable name="doc" select="document(.....)"/>
<xsl:variable name="linkdat" select="document($doc/rss/channel/item/link)"/>
<xsl:value-of select="$linkdat/dog/breed"/>
and I get nothing. But if I try:
<xsl:variable name="doc" select="document(.....)"/>
<xsl:variable name="linkdat" select="document($doc/rss/channel/item/link)"/>
<xsl:value-of select="$linkdat"/>
it returns ALL the data contained in the nodes found in the document $linkdat. How can I just select just one node? Thanks in advance.
PS. Ordered the book but it hasn't arrived yet.
|
|

March 5th, 2009, 08:51 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I can't tell you why /dog/breed selects nothing in the target document without seeing the target document. Presumably it is an incorrect path. It can be useful to do
<debug variable="linkdat">
<xsl:copy-of select="$linkdat"/>
</debug>
to help with debugging.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

March 5th, 2009, 09:26 AM
|
|
Authorized User
|
|
Join Date: Feb 2009
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Here's the target document:
When I tried:
<debug variable="linkdat">
<xsl:copy-of select="$linkdat"/>
</debug>
It just returned all the data like before. In the case of the sample target document above this would be:
NUI3MDdUYWJjZGVmZ2hpamtsbW5vcHFyChow80.0
Thanks for all the help. I'm sure this will all sink in in time.
Rob
|
|

March 5th, 2009, 09:55 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
The elements dog and breed are in a namespace, so you need to use a prefix when referring to them:
<xsl:apply-templates select="$linkdat/d:dog/d:breed"
xmlns:d="http://xml.dogs.com/names"/>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
The Following User Says Thank You to mhkay For This Useful Post:
|
|
|

March 5th, 2009, 10:03 AM
|
|
Authorized User
|
|
Join Date: Feb 2009
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
That was it. Thanks again for the great help!
Rob
|
|
 |