[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] transforming based on implicit cross-references
Subject: RE: [xsl] transforming based on implicit cross-references From: "Robby Pelssers" <robby.pelssers@xxxxxxxxx> Date: Thu, 17 Dec 2009 20:47:55 +0100 |
I haven't tested this but the snippet below should do the thing you want. Cheers, Robby Pelssers <xsl:param name="personOfIntrest"/> <xsl:template match="/"> <result> <xsl:apply-templates/> </result> </xsl:template> <xsl:template match="timestamp[count(people/person = $personOfIntrest) > 0]"> <timestamp> <xsl:apply-templates select="people/person[/text() = $personOfIntrest]"/> </timestamp> </xsl:template> <xsl:template match="person"> <xsl:variable name="position" select="position()"/> <xsl:copy-of select="."/> <!-- copy the location at the same position --> <xsl:copy-of select="../locations/location[position() = $position]"/> </xsl:template> -----Original Message----- From: FAIR, ED (ATTCINW) [mailto:EF7193@xxxxxxx] Sent: Thursday, December 17, 2009 8:23 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] transforming based on implicit cross-references I am a rank beginner using xslt 1.0 (Solaris 9 xsltproc) and I am being provided xml data as in this example: -------------------------8<-------------------- <timestamp>20091216 <people> <person> Peter </person> <person> Robert </person> <person> Anna </person> <locations> <location> New York </location> <location> Zurich </location> <location> Hong Kong </location> </locations> </people> </timestamp> <timestamp>20091217 <people> <person> Anna </person> <person> Peter </person> <person> Jason </person> <person> Robert </person> <locations> <location> Tokyo </location> <location> Trenton </location> <location> Zurich </location> <location> Mumbai </location> </locations> <people> </timestamp> -------------------------8<-------------------- Notice that: - within each <timestamp> the count of "people/person" nodes == the count of people/locations/location" nodes. In the first <timestamp>, there are three people/person nodes, and there are three corresponding people/locations/location nodes. In the second <timestamp> there are four. . - The document order of timestamp/people/person corresponds to the document order of timestamp/people/locations/location. For example, on 20091216 Anna was in Hong Kong; and on 20091217 Anna was in Tokyo. - The document order of <person> can change: in the First <timestamp>, document order is: Peter, then Robert, then Anna; in second <timestamp>, the document order is: Anna, then Peter, then Jason, then Robert. The names will always be distinct (there is always just one Anna, just one Robert, etc). My transformation needs to output just the locations for one person of interest, for example, if I'm interested in Robert: <timestamp>20091216 <person> Robert </person> <location> Zurich </location> </timestamp> <timestamp>20091217 <person> Robert </person> <location> Mumbai </location> </timestamp> Is this possible to perform this transformation in my environment? Thank you in advance, ed
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] transforming based on implici, FAIR, ED (ATTCINW) | Thread | RE: [xsl] transforming based on imp, Syd Bauman |
[xsl] transforming based on implici, FAIR, ED (ATTCINW) | Date | [xsl] [ANN] Meta Data Round-Trippi, Gannon Dick |
Month |