xsl-list
[Top] [All Lists]

Re: [xsl] document tree fragments

2008-10-11 08:37:52
At 2008-10-11 21:31 +1300, Joe Barwell wrote:
I have succeeded, but with two problems. Firstly, I am unable to separately specify the directory path of the files. Here is my "base" xml file's content:

<docs path="jb">
        <doc filename="jb/wine1.xml" />
        <doc filename="jb/wine2.xml" />
        <doc filename="jb/wine3.xml" />
        ...
</docs>

Note that I have provided the directory path within the @filename attribute, but I would prefer to retrieve it from the @path attribute.

Is it true that you want *only* the filename of @filename to be added to @path, or do you want that portion of @filename that matches @path to be removed and if there are more directory steps they are to be included?

In XSLT 1.0 you will have to use extension functions to work with manipulated versions of the attributes. If you gave up on the @path attribute and only used @filename, then you don't need to resort to extensions and you can use:

  document(/docs/doc/@filename)

... to get a node set of the document nodes of all of the files. If you have to do any manipulation on each filename then you have to resort to using extension functions.

<xsl:template match="/docs">
        <xsl:variable name="thePath" select="@path" />
<xsl:variable name="theWines" select="document(doc/@filename)/wine" />
...

Is there a way to use my $thePath variable, instead of including the directory path inside the @filename attribute? I tried to concatenate, but without success.

No, there is no way without creating a secondary structure with the values you want and then using an extension in XSLT 1.0 to read that structure as a node set.

I want to deal with all my xml files together, rather than using a for-each loop, because of several aggregate processes that I want to apply.

Yes, your algorithms will work better when you deal with them all together as a node set of root nodes or document elements.

Secondly, I'm not sure I fully understand what my $theWines variable now contains. I believe it is a collection of tree fragments--i.e. there's no single top-most node, is that right? Or is there an implicit / (document) node?

No ... if you open five files you end up with a node set of five nodes.

The reason I ask is because I have some templates that rely on processing the preceding axis, and whereas my templates work fine for my < wines > xml file, they do not produce the anticipated results when using my $theWines variable.

Correct ... trees are independent of each other. The processor keeps an implicit order (of its own determination) *between* trees, but there are no axes that span across trees.

You need to do grouping cross multiple trees which is done using the variable-based method.

Since you haven't posted examples, I'll sketch out what you need without testing it:

  <xsl:variable name="countries" select="$wines/wine/countries/country"/>
  <table>
    <xsl:for-each select="$countries">
      <xsl:sort select="name"/>
      <!--create a list when encountering the first of them all-->
      <xsl:if test="generate-id(.)=
                    generate-id($countries[name=current()/name][1])">
        <xsl:variable name="this-country"
                      select="$countries[name=current()/name]"/>
        <tr>
          <td>
            <xsl:value-of select="name"/>
            <xsl:value-of select="count($this-country)"/>
            ...

Do I need to wrap the sequence of tree fragments in my $theWines variable inside a node?

You could but then you'd have to use an extension (the same node set extension) to access the resulting tree ... the above variable method works without extensions and across multiple trees in XSLT 1.0.

Chapter 9 of my PDF book and XSLT video goes into the three methods of grouping in XSLT 1.0 (axis, key and variable) and when to use each (and how XSLT 2.0 is so very superior).

I hope this helps.

. . . . . . . . . . . . Ken

--
Upcoming XSLT/XSL-FO hands-on courses:      Wellington, NZ 2009-01
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video sample lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg
Video course overview:  http://www.youtube.com/watch?v=VTiodiij6gE
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>