Subject: Re: [xsl] Catch ALL | Failed template rule From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Tue, 22 Mar 2005 15:01:15 -0500 |
Transform XML into XML. The resulting XML will be a series of pass and fails where specific template rules have a match. So you might be asking questions like, does my element have an attribute "a" who's value is "b"? Or actually, you'd ask the question: if my element has an attribute "a" who's value is "b" then append the attribute "pass" = "1" to the resulting XML, otherwise, append the attribute "pass" = "0".
Example XML: <foo> <bar a="c"/> <bar a="b"/><!-- passes --> <bar a="a"/> <bar a="b"/><!-- passes --> </abc>
You would then: <xsl:apply-template select="foo/bar[@a='b']" mode="matchedresults"/>
And match on: <xsl:template match="bar" mode="matchedresults"> <!-- append element "pass" = "1"--> </xsl:template>
At this point, there is no way to have an "unmatched" template result, and this does make sense to me.
I guess I was looking for the cleanest way to exercise this. I guess it would be this: <xsl:apply-template select="not(foo/bar[@a='b'])" mode="unmatchedresults"/>
<xsl:template match="bar[@a='b']"> <!-- this template matches bar elements you want to pass --> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:attribute name="pass">1</xsl:attribute> <xsl:apply-templates/> </xsl:copy> </xsl:template>
<xsl:template match="bar[not(@a='b')]"> <!-- this template matches bar elements you want not to pass --> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:attribute name="pass">0</xsl:attribute> <xsl:apply-templates/> </xsl:copy> </xsl:template>
Cheers, Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Catch ALL | Failed templa, Michael Kay | Thread | Re: [xsl] Catch ALL | Failed templa, omprakash . v |
RE: [xsl] Catch ALL | Failed templa, Michael Kay | Date | RE: [xsl] undeclared namespace erro, Michael Kay |
Month |