[xsl] creating arbitrary document references

Subject: [xsl] creating arbitrary document references
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 28 May 2019 20:37:47 -0000
Hello --

I'm using XSLT 3.0 in oXygen 21.1.

I have a directory structure of test documents generated by oXygen from
(specialized) DITA XSD schemas.

The schema generation process creates attribute cross reference
attribute values; these do not resolve to an actual file.  If I want the
cross reference values to validate fully by oXygen DITA validation,
the attribute value has to contain some actual file name or
resolvable path.

Using the recursive form of the EXPath function file:list() will get me
all the documents in the test document directory structure.  So
presumably what I want to do is to permute the list of document
locations into some random order using the permute form of
random-number-generator() and then cycle through that list replacing
each cross reference as I come to it with the next item in the list.

Only of course that doesn't work at all; that's the mutable variable
solution. Stuff the permuted list on to a global stack at the start, and
then pop the stack as a value is wanted.  (And if the stack runs out,
shove the permuted sequence on to it again.)

A random number solution,
<xsl:variable name="pick" 
    select="(((random-number-generator(current-dateTime())('number') * $range) mod $range) + 1) => xs:integer()"/>

and then using $docNameSequence[$pick] to get a document name to
reference gives me the same result each time.  Reading the specification
for random-number-generator() leaves me thinking that this is the
correct behaviour.

I care that the references are different, but not that they're in some
order.  So the "I don't know in what order the template is going to
match various xref/@href nodes" isn't important.  And it's not at all
hard to get the sequence of file references available in the directory
structure of test documents.  I absolutely do not know that I have more
files to reference than references to files, or the other way around;
any useful solution needs to cope gracefully with either case.

So how can I pick a random member of that sequence of
files-available-to-be-referenced each time the template matches and I
need to replace the value of @href with that arbitrary actual file


Current Thread