Re: [xsl] How can I match some elements with cross-referencing?

Subject: Re: [xsl] How can I match some elements with cross-referencing?
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 16 Aug 2022 11:17:44 -0000
Am 16.08.2022 um 13:09 schrieb Richard Kerry richard.kerry@xxxxxxxx:
>
> I am putting together an XSL stylesheet to convert the format of some
> XML files [1].B  I have a situation where I think I need some sort of
> cross-referencing within the file for setting the template matches,
> but I donbt know how I might achieve that.
>
> By that I mean that there are elements, lets call them type A, which
> use a regular expression in their match specs, and when found it is
> also necessary to find some related elements, type B, and rewrite them
> (or delete them).
>
> I would appreciate some advice on what sort of method to use for this.
>
> I think I can see three ways I might approach this.
>
>  1. On finding the type A element, its action includes finding the B
>     element and rewriting it.B  This ties all the processing to one
>     template match.
>  2. Two separate templates.B  One matches elements A and processes
>     them.B  The other matches elements of type B and includes some kind
>     of look-up of any corresponding type A element.
>  3. Extra passes.B  First pass to extract a list of names, and second
>     pass to use that in the match spec, if possible.
>
> Ibm not sure whether the first of these is even possible.B  It includes
> one template match of an element rewriting another element entirely.B 
> Thatbs not XSLbs usual model and I donbt think it can be done, can
it?
>
> If the second option is the way to go, how should I go about defining
> the B element match to include the bcross referenceb, ie the search to
> establish whether there is a corresponding AB  element?
>
> There is not a 1:1 correspondence between the two types.B  Not all B
> elements have a corresponding A element.
>
> So, to make it more concrete, letbs say we have some A elements like
this:
>
> <A name=bn1.ub>Contents of A[n1]</A>
>
> <A name=bn2.ub>Contents of A[n2]</A>
>
> <A name=bn3.ub>Contents of A[n3]</A>
>
> And some B like this:
>
> <B reference=bn1.ub>Contents of B[n1]</B>
>
> <B reference=bn2.ub>Contents of B[n2]</B>
>
> <B reference=bn3.ub>Contents of B[n3]</B>
>

Use a key e.g.

 B  <xsl:key name="a" match="A[matches(@name, b(.+).ub)]" use="@name"/>


and then e.g.

 B  <xsl:template match="B[key('a', @reference)]"/>

Current Thread