Re: Parsing XML files as text with collection()

Martin Honnen <[email protected]> Fri, 9 Oct 2020 16:36:33 +0200
Newsgroups gmane.text.xml.saxon.help
Message-ID <[email protected]>
Am 09.10.2020 um 16:17 schrieb Martin Honnen:
> Am 09.10.2020 um 14:31 schrieb Imsieke, Gerrit, le-tex:

>> The documentation says that Saxon will use heuristics to infer the type
>> of file. How can I force Saxon to read every *.xml file, although it may
>> appear as an XML document, as text?
>
> With Saxon (tested with HE 10.2 Java) from the command line I have no
> problems to use uri-collection and unparsed-text in XQuery or XSLT e.g.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>      xmlns:xs="http://www.w3.org/2001/XMLSchema"
> exclude-result-prefixes="#all" version="3.0">
>
>      <xsl:param name="uri" as="xs:string"
>          >file:/C:/SomePath/SomeFolder/</xsl:param>
>
>      <xsl:param name="pattern" as="xs:string"><![CDATA[<\?xml
> .*?>\s*<!DOCTYPE .*?>]]></xsl:param>
>
>      <xsl:template name="xsl:initial-template">
>          <xsl:sequence
>              select="uri-collection($uri || '?select=*.xml') !
> (unparsed-text(.) => replace($pattern, '') => parse-xml())"
>          />


It also works with collection if you use the metadata option:

    <xsl:template name="xsl:initial-template">
         <xsl:sequence
             select="collection($uri ||
'?select=*.xml;metadata=yes;on-error=warning') ! (unparsed-text(?name)
=> replace($pattern, '') => parse-xml())"
         />
     </xsl:template>



_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help