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

RE: transforming based on implicit cross-references

Subject: RE: transforming based on implicit cross-references
From: "Robby Pelssers" <robby.pelssers@xxxxxxxxx>
Date: Thu, 17 Dec 2009 20:47:55 +0100
RE:  transforming based on implicit cross-references
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)
&gt; 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:  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

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.