Subject: [xsl] Random Namespaces Declared with XSLT Stylesheet... why? From: "Jimmy Cerra" <jimbolist@xxxxxxxxxxx> Date: Thu, 19 Jun 2003 04:06:09 -0400 |
I've been hacking a quick-and-dirty transform for turning a custom language [1] into HTML (for presentation), but I've got some odd behavior. The stylesheet seems to randomly put namespace declarations where they're not needed. Why is it doing this? Note: * I'm using Xalan-J for transforms. * The stylesheet can be found at [2]. * The input document can be found at [3]. * The output document can be found at [4]. Oddly, the stylesheet works in Internet Explorer 6 (with msxml.net installed) but not in Mozilla (version 1.4b tested). The Stylesheet is also transcribed (with tabs converted into double-spaces for the fixed-length nature of the email) at the end of this email, but I still have the links posted [5]. -- Jimmy Cerra ] "If the path is set in stone, ] use a sledgehammer." - Me [1] It's an experimental XML syntax for RDF. [2] http://www.pitt.edu/~jfcst24/2003/06/17/rdf/basic/x/XMLSchema-descriptio nx-stylesheet.xsl [3] http://www.pitt.edu/~jfcst24/2003/06/17/rdf/basic/x/XMLSchema-descriptio n1.xml [4] http://www.pitt.edu/~jfcst24/2003/06/17/rdf/basic/x/test.html [5] Garenteed online until 7/18/2003 or my bandwith runs out. ;-) Stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns = "http://www.w3.org/1999/xhtml" xmlns:dc = "http://purl.org/dc/elements/1.1/" xmlns:rdf = "http://www.purl.org/jfc/2003/06/17/rdf/basic/x#" xmlns:xsd = "http://www.w3.org/2001/XMLSchema" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <!-- match templates --> <xsl:template match="/"> <html> <head> <title>RDF Graph</title> </head> <body> <xsl:apply-templates select="rdf:graph" /> </body> </html> </xsl:template> <xsl:template match="rdf:graph"> <xsl:apply-templates select="./rdf:subject" /> </xsl:template> <xsl:template match="rdf:subject"> <h1 style="font-size: 125%">Description of <xsl:choose> <xsl:when test="contains(@rdf:name,'|')"> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:call-template name="rname2uri"> <xsl:with-param name="rname" select="@rdf:name" /> <xsl:with-param name="context" select="." /> </xsl:call-template> </xsl:attribute> <xsl:value-of select="substring-after(@rdf:name,'|')" /> </xsl:element> </xsl:when> <xsl:otherwise> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="@rdf:name" /> </xsl:attribute> <xsl:call-template name="substring-after-last-mod"> <xsl:with-param name="input" select="@rdf:name" /> <xsl:with-param name="substr" select="'/'" /> </xsl:call-template> </xsl:element> </xsl:otherwise> </xsl:choose></h1> <table border="1" style="margin:0em 1em 2em 1em"> <tr> <th align="right" style="padding-right:.75em" width="25%">Property</th> <th align="left" style="padding-left:.75em">Value</th> </tr> <xsl:apply-templates select="./rdf:predicate" /> </table> </xsl:template> <xsl:template match="rdf:predicate"> <tr> <td align="right" style="padding-right:.75em"> <xsl:choose> <xsl:when test="contains(@rdf:name,'|')"> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:call-template name="rname2uri"> <xsl:with-param name="rname" select="@rdf:name" /> <xsl:with-param name="context" select="." /> </xsl:call-template> </xsl:attribute> <xsl:value-of select="substring-after(@rdf:name,'|')" /> </xsl:element> </xsl:when> <xsl:otherwise> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="@rdf:name" /> </xsl:attribute> <xsl:call-template name="substring-after-last-mod"> <xsl:with-param name="input" select="@rdf:name" /> <xsl:with-param name="substr" select="'/'" /> </xsl:call-template> </xsl:element> </xsl:otherwise> </xsl:choose> </td> <td style="padding-left:.75em"> <xsl:choose> <xsl:when test="@rdf:object"> <xsl:choose> <xsl:when test="contains(@rdf:object,'|')"> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:call-template name="rname2uri"> <xsl:with-param name="rname" select="@rdf:object" /> <xsl:with-param name="context" select="." /> </xsl:call-template> </xsl:attribute> <xsl:value-of select="substring-after(@rdf:object,'|')" /> </xsl:element> </xsl:when> <xsl:otherwise> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="@rdf:object" /> </xsl:attribute> <xsl:call-template name="substring-after-last-mod"> <xsl:with-param name="input" select="@rdf:object" /> <xsl:with-param name="substr" select="'/'" /> </xsl:call-template> </xsl:element> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="node()" /> </xsl:otherwise> </xsl:choose> </td> </tr> </xsl:template> <!-- named templates --> <xsl:template name="rname2uri"> <xsl:param name="rname" /> <xsl:param name="context" /> <xsl:choose> <xsl:when test="contains($rname,'|')"> <xsl:value-of select="concat( namespace::*[name(.)=substring-before($rname,'|')], substring-after($rname,'|'))" /> </xsl:when> <xsl:otherwise> <xsl:message terminate="no">Warning, <xsl:value-of select="$rname" /> does not contain '|'</xsl:message> <xsl:value-of select="$rname" /> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="htmlNamespaceTable"> <table border="1"> <xsl:for-each select="namespace::*"> <tr><td><xsl:value-of select="name(.)" /></td><td><xsl:value-of select="." /></td></tr> </xsl:for-each> </table> </xsl:template> <!-- copy template from "XSLT Cookbook" by Sal Mangano --> <!-- HIGHLY --> <!-- I recommend the book --> <xsl:template match="node() | @*"> <xsl:copy> <xsl:apply-templates select="@* | node()" /> </xsl:copy> </xsl:template> <!-- substring after last occurance also from "XSLT Cookbook"...--> <!-- I should buy Sal Mangano a drink! --> <xsl:template name="substring-after-last"> <xsl:param name="input" /> <xsl:param name="substr" /> <!-- Extract the string which comes after the first occurence --> <xsl:variable name="temp" select="substring-after($input,$substr)" /> <xsl:choose> <!-- If it still contains the search string then recursively process --> <xsl:when test="$substr and contains($temp,$substr)"> <xsl:call-template name="substring-after-last"> <xsl:with-param name="input" select="$temp" /> <xsl:with-param name="substr" select="$substr" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$temp" /> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- my modifications of above template --> <!-- outputs $input instead of null if $substr not in $input --> <xsl:template name="substring-after-last-mod"> <xsl:param name="input" /> <xsl:param name="substr" /> <xsl:choose> <xsl:when test="contains($input,$substr)"> <xsl:call-template name="substring-after-last"> <xsl:with-param name="input" select="$input" /> <xsl:with-param name="substr" select="$substr" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$input" /> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] DOM and XPath Data Model, Michael Kay | Thread | RE: [xsl] Random Namespaces Declare, Michael Kay |
RE: [xsl] Summating/grouping, Rob Anderson | Date | RE: [xsl] Random Namespaces Declare, Jarno . Elovirta |
Month |