A sequence of more than one item is not allowed as the first argument of fn:doc-available() xslt 2 3

Viewed 13

I have an XML document that is a list of XML documents:

dmIndex.xml:

<dmIndex>
    <dmFile href="DME-SF518-CCC-AAA-D00-00-00-00AA-131A-00_en-US.XML"
            dmIndex="S1000D-AAA-D00-00-00-00AA-131A-A"/>
   <dmFile href="DME-SF518-MMM-AAA-D00-00-00-00AA-131A-00_en-US.XML"
            dmIndex="S1000D-AAA-D00-00-00-00AA-131A-A"/>
   <dmFile href="SAMPLE-A-05-21-0010-00AAA-913A-A_EN-US.xml"
            dmIndex="SAMPLE-A-05-21-0010-00AAA-913A-A"/>
   <dmFile href="UPF-AAA-D00-00-00-00AA-00_en-US.XML"
            dmIndex=""/>
   <dmFile href="SAMPLE-A-55-10-0000-00AAA-140A-A_EN-US.xml"
            dmIndex="SAMPLE-A-55-10-0000-00AAA-140A-A"/>
   <dmFile href="SAMPLE-A-95-10-0000-00AAA-140A-A_EN-US.xml"
            dmIndex="SAMPLE-A-95-10-0000-00AAA-140A-A"/>
   <dmFile href="descript_sample.xml" dmIndex="00-0-00-00-00-000-0000-A"/>
   <dmFile href="proced_sample_dmRef_Checkout.xml"
            dmIndex="SAMPLE-A-05-10-0000-00AAA-913A-A"/>
   <dmFile href="DMC-FJ-A-00-00-00-00A-003A-A.xml"
            dmIndex="FJ-A-00-00-00-00A-003A-A"/>
</dmIndex>

xslt:

<xsl:param name="dmIndex" select="'dmIndex.xml'"/>

<xsl:template match="/">
  <xsl:variable name="dmRefFile" select="document($dmIndex)//dmFile[@dmIndex='S1000D-AAA-D00-00-00-00AA-131A-A']/@href"/>
  <xsl:if test="doc-available($dmRefFile)">
    <xsl:apply-templates select="document($dmRefFile)/dmodule"/>
  </xsl:if>
</xsl:template>

I'd like to test if the document exists before processing, but I'm getting the error: A sequence of more than one item is not allowed as the first argument of fn:doc-available()

@dmIndex is not unique and can be empty, but I don't know how to filter the select statement correctly to return one @href. I've tried [1] in different places:

document($dmIndex)//dmFile[@dmIndex='S1000D-AAA-D00-00-00-00AA-131A-A']/@href[1]
document($dmIndex)//dmFile[@dmIndex='S1000D-AAA-D00-00-00-00AA-131A-A'][1]/@href
doc-available($dmRefFile[1])

I'm open to a better way of testing dmRefFile, it would only be for XML files.

1 Answers

I think you want e.g. <xsl:apply-templates select="doc($dmIndex)//dmFile[@dmIndex='S1000D-AAA-D00-00-00-00AA-131A-A']/@href[doc-available(.)]/doc(.)/dmodule"/>

Related