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

Re: Data-driven Display of records with variable numbe

Subject: Re: Data-driven Display of records with variable number of fields
From: "Rich Caloggero" <rjc@xxxxxxx>
Date: Fri, 10 Dec 2004 12:18:51 -0500
rich caloggero
Thanx Wendell. This worked out fine!

-- Rich

----- Original Message -----
From: "Wendell Piez" <wapiez@xxxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, December 09, 2004 6:46 PM
Subject: Re:  Data-driven Display of records with variable number of
fields


> Rich,
>
> The usual approach to this is to use the name() or local-name() function
to
> extract the names of your elements as strings, and then do string testing
> against those names in the predicate of an XPath, to select them.
>
> So when your context node is an unknown element type, you can still get
all
> the nodes of that type that are, say, children of some othe node $parent,
> by saying
>
> $parent/*[name()=name(current())]
>
> ... you can even parameterize a name (again as a string) and pass it
around
> between templates.
>
> So let's say you wanted to process a set of $records ... you could say
>
> <xsl:for-each select="$records">
>    <xsl:variable name="thisrecord" select=".">
>    <xsl:for-each select="/headers/*">
>      <xsl:apply-templates
>        select="$thisrecord/*[local-name()=local-name(current())]"/>
>    </xsl:for-each>
> </xsl:for-each>
>
> ... which applies templates only to the children of each member of
$records
> whose names appear as the name of an element child of /headers, in the
> order they appear there. (In this example I used the local-name() function
> so you could keep your elements in separate namespaces if you wanted.)
>
> I hope this is enough to get you going.
>
> Cheers,
> Wendell
>
> At 04:05 PM 12/9/2004, you wrote:
> >Is this possible in xslt-1.0?
> >
> >Given the following input, I want to transform the output such that I get
> >only the fields of each record which I specify in the headers element. I
> >want the order to also be the order in which they appear in the headers
> >element.  So if headers looks like:
> ><headers>
> ><year/> <artist/>
> ></headers>
> >then I want each record in the output to only contain the year and artist
> >fields, in that order.
> >
> >I can't seem to write an xPath expression for this kind of transform
because
> >xPath node tests cannot contain variables. The expression would need to
look
> >something like "/cds/cd/$field", where $field would contain the name of
one
> >of the nodes listen in /headers (see xml below).
> >
> >Thanx for any suggestions...
> >
> >-- Rich
> >
> >Input:
> ><?xml version="1.0" encoding="ISO-8859-1" ?>
> ><?xml-stylesheet type="text/xsl" href="transform.xsl"?><cds>
> ><title>My CD Collection</title>
> ><headers>
> ><title/>
> ><artist/>
> ><year/>
> ></headers>
> >
> ><cd>
> ><artist>Rich Caloggero</artist>
> ><title>A Taste of Tranquility</title>
> ><year>2004</year>
> ><label>Touch the Sky Music</label>
> ></cd>
> >
> ><cd>
> ><artist>The Grateful Dead</artist>
> ><title>Europe 72</title>
> ><year>1972</year>
> ></cd>
> ></cds>
> >
> >
> >
> >-- Rich
> >"In the end, our society will be defined not only by what we create, but
by
> >what we refuse to destroy."
> >-John C. Sawbill (1936-2000), president, The Nature Conservancy,
1990-2000
>
>
> ======================================================================
> 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.