Project

Profile

Help

namespaces trouble

Added by Anonymous almost 18 years ago

Legacy ID: #3808913 Legacy Poster: Chris Dupuy (exuviae)

I am using Saxon-B 8.7.3 and am having some trouble with empty namespaces. I did a search and read the previous post but they did not help. As i understand it if i have an xml that looks like this: <scnCDR xmlns="http://www.foobar.net/cdr&quot;&gt;&lt;startTime&gt;2006-06-26T12:06:46-05:00&lt;/startTime> <endTime>2006-06-26T12:17:31-05:00</endTime> </scnCDR> and some xslt that looks like this: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:cdr="http://www.foobar.net/cdr" version="2.0"> <xsl:output method="text" encoding="UTF-8"/> <xsl:template match="/"> <xsl:call-template name="callStateProgress"> <xsl:with-param name="recordType">99</xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template name="callStateProgress"> <xsl:param name="recordType" select='test'/> <xsl:value-of select="fn:normalize-space(cdr.scnCdr/startTime)"/> <xsl:value-of select="fn:normalize-space('|')"/> </xsl:template> </xsl:stylesheet> the xpath statements cdr.scnCDR/startTime should result in the data 2006-06-26T12:06:46-05:00| but i get is | the data in startTime is never found. The code i use to parse this is fairly simple: ByteArrayInputStream xmlBtsStream = new ByteArrayInputStream(xmlBts); ByteArrayInputStream xsltBtsStream = new ByteArrayInputStream( xsltBytes); Source xmlSource = new StreamSource(xmlBtsStream); Source xsltSource = new StreamSource(xsltBtsStream); // the hard way to show going from bytes to streams as you would in // a prod env ByteArrayOutputStream bstream = new ByteArrayOutputStream(); PrintStream pstream = new PrintStream(bstream); Result result = new StreamResult(pstream); // create an instance of TransformerFactory TransformerFactory transFact = TransformerFactory.newInstance(); // transform the data Transformer trans = transFact.newTransformer(xsltSource); trans.transform(xmlSource, result);


Replies (1)

RE: namespaces trouble - Added by Anonymous almost 18 years ago

Legacy ID: #3809042 Legacy Poster: Michael Kay (mhkay)

Your scnCDR element should be referred to in the path expression as cdr:scnCDR, not as cdr.scnCdr; and your startTime element should be referred to as cdr:startTime. Note also that there is no need to prefix the names of standard XPath functions. If you made your stylesheet schema-aware, then instead of getting blank output, you would get a compile-time error message telling you what you have done wrong. (Please note, this is an XSLT coding question, not anything specific to Saxon. Therefore, it would be better asked on the xsl-list at www.mulberrytech.com)

    (1-1/1)

    Please register to reply