xml - xslt result-document overwrite or skip file with duplicate uri -
is there way make xsl:result-document overwrite or skip files when output files have duplicate uri ? think don't have provide example. have database duplicate entries in it. know can put id , remove id names of 60000 files
best regards.
it seems xslt 3.0 can catch error write output uri twice using xsl:try/xsl:catch
, given stylesheet
<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" xmlns:err="http://www.w3.org/2005/xqt-errors" exclude-result-prefixes="xs math" version="3.0"> <xsl:mode streamable="yes"/> <xsl:output method="text"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> <xsl:apply-templates select="copy-of(root/record)" mode="result"/> </xsl:template> <xsl:template match="record" mode="result"> <xsl:try> <xsl:result-document href="{fname}.txt" method="text"> <xsl:value-of select="* except fname" separator=","/> </xsl:result-document> <xsl:catch errors="err:xtde1490"> <xsl:message select="'attempt write more once ', fname"/> </xsl:catch> </xsl:try> </xsl:template> </xsl:stylesheet>
and input like
<?xml version="1.0" encoding="utf-8"?> <root> <record> <fname>result1</fname> <foo>1</foo> <bar>a</bar> </record> <record> <fname>result2</fname> <foo>2</foo> <bar>b</bar> </record> <record> <fname>result1</fname> <foo>1</foo> <bar>a</bar> </record> </root>
saxon 9.8 ee processes input streaming , writes 2 result files while catching error when trying write second time result1.txt
when processing third record.
as @michaelkay's comment implementation dependency duplicates caught, agree that, if matters avoid can replace
<xsl:template match="/"> <xsl:apply-templates select="copy-of(root/record)" mode="result"/> </xsl:template>
with use of xsl:iterate
<xsl:template match="/"> <xsl:iterate select="root/record"> <xsl:apply-templates select="copy-of()" mode="result"/> </xsl:iterate> </xsl:template>
that way think sequential processing done.
Comments
Post a Comment