- From: Erik Siegel <erik@xatapult.nl>
- Date: Thu, 29 Jan 2026 14:18:51 +0100
- To: Don Smith <dsmith_lockesmith@yahoo.com>, Dev XProc <xproc-dev@w3.org>
- Message-ID: <c4dcb38e-417d-4663-9510-5fbf32036cee@xatapult.nl>
Hello Don,
The spec clearly says that when collection="true" the context item is
undefined. You can access the collection through the collection()
function, so something like collection()/c/@s might work (depending on
whether there's only one /c/@s)
However, I haven't tested this, but I'm doubtful about your way of
accessing files collection through the href attribute.
Maybe something like: <p:variable name="..."
select="collection('files')/c/@s"/> ??? (no collection="true")
And as a general remark: it is best practice to type your variables, so
add an as="..." attribute with the intended outcome type.
Hope this helps, maybe not as a definite answer but as a tip.
Regards,
Erik Siegel
On 29/01/2026 13:00, Don Smith wrote:
> I'm using Morgana 1.4.5 on Windows.
>
> I want load a collection of XML files into a variable and then
> retrieve information from one specific file but have been unable to
> get it to work. I've a simplified example of the code I've got so far,
> but here's a summary of the steps:
>
> 1. Establish source and result ports. Source file is input-main.xml
> 2. Create variable "new_s_value" to get collection of files in
> subfolder "files"; use the unique root element of the target file to
> identify the correct file in the collection and then get the desired
> attribute value from the root element
> 3. Re-write the value of the target attribute "s" in the source file
> using the new value from the collection (XSLT transform)
> 4. Output the new version of the input
>
> As you can see below (also in files in zip attachment), all this works
> if I don't use a collection on the variable "new_s_value". But that's
> only a test. I need to use a collection on variable "new_s_value"
> because I won't ever be able to know the name of the target file. But
> I'm missing something about how to access a collection on the
> variable. The error I get from Morgana is
>
> "Error in XPath expression '/c/@s': Context item is needed, but not
> provided: 1 items found"
>
> I've been unable to determine how to provide the missing XPath
> context; I thought the @href would provide it but apparently not.
>
> XPROC:
> <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="3.0"
> name="main-step">
> <p:input port="source" primary="true" href="input-main.xml" />
> <p:output port="result" primary="true" sequence="true"/>
> <!-- this works but is only a test -->
> <!--<p:variable name="new_s_value" href="files/z3.xml"
> select="/c/@s" />-->
> <p:variable name="new_s_value" collection="true"
> href="{collection(files)}" select="/c/@s" />
> <p:xslt message="new s value: {$new_s_value}"
> parameters="map{'new_s_value': $new_s_value}">
> <p:with-input port="stylesheet" href="rewrite-s-value.xsl"/>
> </p:xslt>
> <p:store href="stored/rewrite-s-value.xml"></p:store>
> </p:declare-step>
>
> INPUT FILE input-main.xml
> <sample-source s="z5">
> <div>
> <section s="z5">
> <title>Section level 1 title content.</title>
> <div>
> <section s="z5">
> <title>Section level 2 title content.</title>
> </section>
> </div>
> </section>
> </div>
> </sample-source>
>
> COLLECTION FILES IN SUBFOLDER "files"
> z1.zml
> <z s="no1">
> <p>Z document with a paragraph.</p>
> </z>
>
> z2.xml
> <y s="no2">
> <p>Y document with a paragraph.</p>
> </y>
>
> z3.xml
> <c s="t9">
> <p>C document with a paragraph.</p>
> </c>
>
> XSLT rewrite-s-value.xsl
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:math="http://www.w3.org/2005/xpath-functions/math"
> exclude-result-prefixes="xs math"
> version="3.0">
> <xsl:param name="new_s_value" as="xs:string">default</xsl:param>
> <xsl:template match="*">
> <xsl:copy>
> <xsl:if test="@s">
> <xsl:attribute name="s" select="$new_s_value"/>
> </xsl:if>
> <xsl:apply-templates/>
> </xsl:copy>
> </xsl:template>
> </xsl:stylesheet>
>
> Thanks,
>
> Don
>
>
>
Received on Thursday, 29 January 2026 13:19:31 UTC