[xsl] Addressing siblings

Subject: [xsl] Addressing siblings
From: <David.McKay@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 9 Feb 2005 09:28:05 -0000
--- XSL Processor Details

Vendor: SAXON 6.5.3 from Michael Kay
Vendor URL: http://saxon.sf.net/


Say I have some (grossly simplified, politically incorrect, and exclusive of
alternate lifestyles) XML which looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
   <Man name="Bob" wife="Alice" birth="1960-08-15"/>
   <Woman name="Alice" birth="1955-10-26"/>

To cut a long story short, I have an xsl template which scopes Woman, and I
want to set a variable to be that Woman's husband (ie the Man for whom the
Woman is the wife). I've come up with the following method:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   <xsl:output method="text" indent="no" encoding="UTF-8"/>

   <xsl:template match="/">

   <!-- various processing -->

   <xsl:template match="Man" mode="husband">
      <xsl:value-of select="@name"/>

   <xsl:template match="Woman" mode=>
      <xsl:variable name="me" select="@name"/>
      <xsl:variable name="husband">
         <xsl:apply-templates mode="husband" select="../*[@wife=$me]"/>

      <!-- do something with $husband -->

Is there a more compact way (especially since I would want to access the birth
attribute too)? I thought something along the lines of the following might
work, but I couldn't figure out how.

<xsl:variable name="husband-birthday" select="../*[@wife=./@name]/@birth"/>


Dave McKay


The information contained in this e-mail is confidential. It may also
be legally privileged. It is intended only for the stated addressee(s)
and access to it by any other person is unauthorised. If you are not
an addressee, you must not disclose, copy, circulate or in any other
way use or rely on the information contained in this e-mail. Such
unauthorised use may be unlawful.

If you have received this e-mail in error, please inform
Racal Instruments Group Ltd. immediately by
    emailing  postmaster@xxxxxxxxxxxxxxxxxxxxxxxxxxx
    phoning +44 (0)1202 872800  (ask for the I.T. Dept.)
and delete it and all copies from your system.



Current Thread