[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Attempting *not* to copy certain nodes


Subject: Re: [xsl] Attempting *not* to copy certain nodes
From: 3rett 3onfield <brett@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 14 Jan 2004 12:26:31 -0500

Thanks primarily to members of this list, I've been making good progress in my attempts to apply a XSLT stylesheet to a SOAP download of NYSE, Amex, and NAQDAQ stock information. I really appreciate your guidance.

FWIW, I've found Treebeard ( http://treebeard.sourceforge.net/ ) a very useful tool, easy to install and start using. So far I've also made some use of Cooktop ( http://www.xmlcooktop.com/ ) though I'd prefer to use an open source editor. If anyone has one they find as useful, please post (I've checked Sourceforge, list archives, usenet...).

My goal is to copy to a CSV file the Symbol, CIK, Cusip, and Market
data from the following source file:

---

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="CopySuccessSoap.xslt"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<MapSecuritiesResponse
xmlns="http://www.xignite.com/services/">
<MapSecuritiesResult>
<Security>
<Outcome>RequestError</Outcome>
<Message>No match found for this security identifier.</Message>
<Identity>Header</Identity>
<Delay>7.90625</Delay>
<Symbol>AA^</Symbol>
</Security>
<Security>
<Outcome>Success</Outcome>
<Delay>0</Delay>
<CIK>0001099290</CIK>
<Cusip>00371F206</Cusip>
<Symbol>AAC</Symbol>
<Name>ABLEAUCTIONS COM INC</Name>
<Market>AMEX</Market>
<CategoryOrIndustry />
</Security>
<Security>
<Outcome>Success</Outcome>
<Delay>0</Delay>
<CIK>0000004611</CIK>
<Cusip>024591109</Cusip>
<Symbol>ABL</Symbol>
<Name>American Biltrite Inc</Name>
<Market>AMEX</Market>
<CategoryOrIndustry>Fabricated Plastic &amp; Rubber</CategoryOrIndustry>
</Security>


...

         </MapSecuritiesResult>
      </MapSecuritiesResponse>
   </soap:Body>
</soap:Envelope>

---

Based on suggestions from members of this list and Google searches I've been able to create the following XSLT:

---

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"
                exclude-result-prefixes="soap-env"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                version="1.0">
<xsl:output method="text" indent="yes" encoding="UTF-8"/>

<xsl:template match="/">
  <xsl:apply-templates select="soap:Envelope/soap:Body/node()"/>
</xsl:template>

<xsl:template match="*"> <!--synthesize element with the input name-->
  <xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

    <xsl:template match="/">
	<xsl:for-each select="MapSecuritiesResult/Security">
		<xsl:if test="Outcome='Success'">
		<xsl:copy-of select="Name"/>, <!--
		--><xsl:copy-of select="Symbol"/>, <!--
		--><xsl:copy-of select="CIK"/>, <!--
		--><xsl:copy-of select="Cusip"/>, <!--
		--><xsl:copy-of select="Market"/>
		<xsl:text>&#13;</xsl:text>
		</xsl:if>
	</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>

---

The code that suppresses the soap namespace is from G. Ken Holman's post:
http://www.biglist.com/lists/xsl-list/archives/200207/msg01649.html

Unfortunately, this seems to generate errors in Saxon (Treebeard's processor), IE, and Firebird. Ken uses semicolons when declaring namespaces, other places they don't ( http://www.xml.com/pub/a/2001/04/04/trxml/ ), but both (or, of course, something else I'm doing wrong) generate errors such that I get no output.

The other problem I've run into is the <xsl:text>&#13;</xsl:text> (line feed, necessary for the CSV) works in Treebeard's Saxon output window but does not work properly with Firebird or IE. Is there a way around this?

Sorry for the long post. Again, thank you for making this list public and for the help I've already received.

Brett


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




Current Thread
Keywords