This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Identifying two tags that share some attribute names and values


Hi folks,

I've been migrating the Kernel Traffic web site (http://kt.zork.net) over to an
XML/XSLT-based production system. So far it looks like something I should have
done years ago. Compilation time (compared with my old home-grown processor)
has dropped from hours to minutes, and the flexibility to add new features
is just amazing.

However, there are still a few things that are giving me problems. One such
boils down to trying to identify a set of tags that share attributes with
a target tag. So for instance I have two files, 1.xml and 2.xml:

----------------------------- 1.xml ---------------------------------
<?xml version="1.0" ?>

<mydata>
<a x="1" y="2" z="3">test</a>
</mydata>
---------------------------------------------------------------------

----------------------------- 2.xml ---------------------------------
<?xml version="1.0" ?>

<outsidedata>
<b x="1" y="2">PPP</b>
<b y="2" z="3">QQQ</b>
<b z="3">RRR</b>
<b x="9" y="8" z="7">SSS</b>
<b m="2" z="3">TTT</b>
</outsidedata>
---------------------------------------------------------------------

Basically, 1.xml represents a newsletter file, and 2.xml is an automatically
generated file that contains cross-reference information. The <a> tag in
1.xml is a cross-reference request that needs to be resolved using data
available in 2.xml.

processing is done on 1.xml, which reads in 2.xml via the document()
function. The XSLT code analyzes 2.xml and looks for all <b> tags whose
attributes precisely match attributes found in the target <a> tag. Note that
not all of <a>'s attributes must be present in a matching <b>, but all of
<b>'s attributes must be present in <a> and must share the same values as
the corresponding attributes in <a>. Also note that <a>'s attributes are not
necessarily "x", "y", and "z", but could be anything. The XSLT code should
not make assumptions about their names or how many there may be.

So in the above example files, <a> contains attributes "x", "y", and "z",
which each have the values "1", "2", and "3" respectively. Looking at 2.xml,
you can see that the first, second and third <b> tags are successful matches,
while the fourth and fifth are not.

What I need is a recipe like the following (except that works ;-):

----------------- XSLT code for processing a.xml --------------------
<!-- Resolve kcrefs -->
<xsl:template match="mydata/a">
<xsl:for-each select="document('2.xml')/outsidedata/b">
[<xsl:value-of select="."/>]
</xsl:for-each>
</xsl:template>
---------------------------------------------------------------------

in which the output would look something like this:

----------------------- Desired output ------------------------------
[PPP]
[QQQ]
[RRR]
---------------------------------------------------------------------

I hope I've described this well enough. I don't even know if it's possible
to do what I'm asking for, though it seems like it should be. Any help would
be greatly appreciated.

Many thanks,
Zack

-- 
Zack Brown


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]