[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Using XSLT 1.0 , I have tried using the Meunchian

Subject: RE: Using XSLT 1.0 , I have tried using the Meunchian methodsolutions on
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 21 Dec 2006 11:22:30 -0500
RE:  Using XSLT 1.0
Dear Robert,

You emailed me off-list on this thread. (I don't know who else you may have asked.) I'm replying, but cc:ing the list.

First, your problem: XPath expressions are evaluated relative to a context node, and since your template is matching the root, that's the context node, so the key is not being called with any values.

Specifically, when you say

<xsl:for-each
 select="key('tar_by_filingtype', concat(FilingType, ' ', AgencyName))">

you are really saying (XPath long syntax):

<xsl:for-each
 select="key('tar_by_filingtype',
         concat(child::FilingType, ' ', child::AgencyName))">

and the XPath "child::FilingType" and "child::AgencyName" are evaluated relative to the context, which here is the root node (since that's what you matched). The root has no such children, so the value sent to the key function is simply " " -- which gets you no nodes back.

To fix this, you need to iterate over nodes which will provide the context you need. Something like this:

<xsl:for-each
select="//MonthlyTARList">
<xsl:sort select="FilingType"/>
<xsl:if test="count(.|key('tar_by_filingtype', concat(FilingType, ' ', AgencyName))[1])=1">
<!-- tests if the current node selected in the for-each is the
first node returned by the key with its values -->
...


Note: this test could also take this form --

test="generate-id() =
      generate-id(key('tar_by_filingtype',
                      concat(FilingType, ' ', AgencyName))[1])"/>

... which I believe is just a bit more legible for beginners as a way of testing whether one node is the same as another.

The equality test is the same as saying, in long syntax

test="generate-id(self::node()) = generate-id(
  key('tar_by_filingtype',
      concat(child::FilingType, ' ', child::AgencyName))[1])"/>

... which is even more explicit at the price of being less legible (unless you don't know XPath in which case you're faking it either way).

More basically, what you're missing appears to me to be the basics of the XSLT processing model -- the design rationale behind the language that explains why we even bother using templates at all. Unknowing of this, you also don't know about critical features of the language like evaluation of XPath relative to a context node, or even what a context node is. Until you master this, you'll never be able to do more than trivial things with the language -- and when you get into things like grouping, not even that.

Also, I'm sorry to say you've broken a couple of rules of list etiquette:

1. You've mailed me off list. Contributors to XSL-List are donating their time and expertise to a public good. You should respect that by doing the same -- if you can't help others by offering solutions and explanations, then ask good questions (or ask bad questions well); in any case, don't impose on individuals (ask the entire group). On the list, experts and novices help each other and look over each others' shoulders to mind how it's all going. You're going outside that process. (Note also that more than one expert posting to the list is also paid to give similar advice privately. By soliciting help off list you may be presuming to get for free what others are paying for.)

Note that this doesn't preclude off-list communication for other reasons than getting unoffered help.

2. You haven't included small but complete code samples, making it possible to diagnose the problem without opening external applications like web browsers and file editors. Often experts can spot problems very quickly; but having to dig in makes it tough for them. Once in a while, when a problem is particularly gnarly, we break this rule on purpose; but you hadn't gotten to that point yet (and indeed your mistake was a very common and basic one for a beginner).

As it happens, today I was in a good (or bad?) mood, so rather than just junking your email with a complaint, I decided to answer it and cc: the list.

Happy holidays,
Wendell

At 05:03 PM 12/20/2006, you wrote:
Thanks for your help, but what I'm I missing? Now none of the data is
displaying.


File: http://tn.gov/sos/pub/tar/MonthlyTARList.xml

Stylesheet:
http://tn.gov/sos/pub/tar/MonthlyTAR.xsl

Robert Greene
Tennessee Department of State
Division of Publications
312 8th Ave. North, 8th Floor
Nashville, TN 37243
(615) 253-4571
FAX (615) 741-5133
http://www.tennessee.gov/sos


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.