Subject: Re: [xsl] filtering problem From: Michael Kay <mike@xxxxxxxxxxxx> Date: Thu, 17 Jun 2010 10:15:15 +0100 |
<xsl:template match="*[. intersect $pathToFirstFailure]"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template>
Michael Kay Saxonica
Hi all,
Consider the following input XML file:
<?xml version="1.0" encoding="UTF-8"?> <batch name="level1"> <command src="1" /> <command src="2" failed="true()" /> <command src="3" /> <command src="4" failed="true()" /> <batch name="level2"> <command src="10" /> <command src="11" failed="true()" /> <command src="12" /> <batch name="level3"> <command src="20" /> <command src="21" failed="true()" /> <command src="22" /> </batch> <command src="30" /> <command src="31" failed="true()" /> <command src="32" /> </batch> </batch>
I need an XSL transformation that scans the top-level batch until it finds a command marked as failed, no matter at which internal batch-level it is, preserving the batch level on the report.
Currently, I have this XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan">
<xsl:output method="xml" indent="yes" encoding="UTF-8" media-type="text/xml" xalan:indent-amount="2" />
<xsl:strip-space elements="*" />
<xsl:template match="/"> <xsl:apply-templates /> </xsl:template>
<!-- FIXME: batches are matched even though there is a prior failed command or batch containing a failed command --> <xsl:template match="batch"> <batch name="{@name}"> <xsl:apply-templates /> </batch> </xsl:template>
<!-- match only the first failing command --> <xsl:template match="command[@failed=true()][1]"> <failed-command src="{@src}" /> </xsl:template> </xsl:stylesheet>
which generates:
<?xml version="1.0" encoding="UTF-8"?> <batch xmlns:xalan="http://xml.apache.org/xalan" name="level1"> <failed-command src="2" /> <batch name="level2"> <failed-command src="11" /> <batch name="level3"> <failed-command src="21" /> </batch> </batch> </batch>
instead of:
<?xml version="1.0" encoding="UTF-8"?> <batch xmlns:xalan="http://xml.apache.org/xalan" name="level1"> <failed-command src="2" /> </batch>
Another example -- if only command[@src='21'] is marked failed, then the generated output should be:
<?xml version="1.0" encoding="UTF-8"?> <batch name="level1"> <batch name="level2"> <batch name="level3"> <failed-command src="21" /> </batch> </batch> </batch>
Thanks for your help, Adrian.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] filtering problem, Adrian Herscu | Thread | [xsl] Re: filtering problem, Adrian Herscu |
Re: [xsl] XSL Processing to avoid r, Michael Kay | Date | RE: [xsl] XSL Processing to avoid r, Fabien Tillier |
Month |