Subject: Re: [xsl] Attempting *not* to copy certain nodes From: "J.Pietschmann" <j3322ptm@xxxxxxxx> Date: Sun, 11 Jan 2004 21:00:49 +0100 |
...<MapSecuritiesResult> <Security> <Outcome>RequestError</Outcome>
I want to copy the <Security> nodes in which the Outcome was Success and want not to copy the ones in which the Outcome was Request Error.
The XSLT file I've used is based on an earlier discussion on this list: http://www.biglist.com/lists/xsl-list/archives/200307/msg01390.html
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
There is no node named "Root" in your XML source.<xsl:template match="Root"> <xsl:apply-templates select="MapSecuritiesResult"/> </xsl:template>
<xsl:template match="Security"> <xsl:copy> <xsl:apply-templates select="Outcome[Success]"/> </xsl:copy> </xsl:template>
This will always copy any Security element, and apply templates to the Outcome child elements which itself have a Success child element. In your XML, the Outcome elements contain the *text* "Succes" (or other text), but no child elements. This means you wont get any output here. The default templates will provide you which some whitespace and possibly other text from outside the Security elements.
Try <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <xsl:copy-of select="Security[Outcome='Success']"/> </xsl:template> </xsl:stylesheet> which should be a bit closer to your expectations. This provides literal copies of all Security elements (with all children) which have an Outcome child element containing the text "Success". You'll probably want to have something else but use this as a start for refinement.
Obviously, it's not working or I wouldn't be asking for help. Sorry if I've not searched the FAQ properly.
Try starting to learn XSLT systematically, using simpler transformations, and perhaps an environment which visualizes XPath selections and how templates are applied (search for "XPath visualizer").
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Attempting *not* to copy , J.Pietschmann | Thread | Re: [xsl] Attempting *not* to copy , 3rett 3onfield |
RE: [xsl] Attempting *not* to copy , Andreas L. Delmelle | Date | Re: [xsl] UBB Code and XSLT, Karl J. Stubsjoen |
Month |