Subject: Re: [xsl] xpath expression in <xsl:stylesheet> element From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Fri, 24 Aug 2001 18:39:50 +0100 |
Hi Annie, > 1) How do I get the "xsi:schemaLocation="http://www.orincon.com/ia > LoginHypothesis.xsd" text to appear? > > 2) Can I use xpath in the <xsl:stylesheet> element to extract this > LoginHypothesis factType value from the input.xml? > > I have tried xsi:schemaLocation="http://www.orincon.com/ia > {ia:unorderedFact/child::factType/text()}.xsd" with no joy. You want the document element *of the result* (the LoginHyphothesis element) to have the xsi:schemaLocation attribute on it. You create the LoginHypothesis element when you do: <xsl:element name="{child::factType/text()}"> ... </xsl:element> in the template that matches the ia:unorderedFact element. You want to add an xsi:schemaLocation attribute on to that element; because you create the element using xsl:element, you have to do this with xsl:attribute: <xsl:element name="{factType}"> <xsl:attribute name="xsi:schemaLocation"> ... </xsl:attribute> ... </xsl:element> (Note: I changed the path for setting the name of the element to make it simpler - it will have exactly the same effect as the one you're using at the moment.) The value of the xsi:schemaLocation attribute is the string 'http://www.orincon.com/ia ' followed by the value of the factType child of the ia:unorderedFact element, which you can get with exactly the same path as you use to get the name of the element you're creating. So you want: <xsl:element name="{factType}"> <xsl:attribute name="xsi:schemaLocation"> <xsl:text>http://www.orincon.com/ia </xsl:text> <xsl:value-of select="factType" /> </xsl:attribute> ... </xsl:element> The XMLSchema-instance namespace will be added to the LoginHypothesis element automatically because it's required for the xsi:schemaLocation element. However, the 'http://www.orincon.com/ia' namespace declaration will not be. I don't think this matters because the namespace declaration will be output as required for an element or attribute in that namespace; the only time when it might be a problem is if you have attribute values that are qualified names, like 'ia:foo'. If you need the ia namespace declaration on the document element of the result, you need to copy the namespace node from either the source document (input.xml) or from the stylesheet itself, as follows: <xsl:element name="{factType}"> <xsl:copy-of select="namespace::ia" /> <xsl:attribute name="xsi:schemaLocation"> <xsl:text>http://www.orincon.com/ia </xsl:text> <xsl:value-of select="factType" /> </xsl:attribute> ... </xsl:element> or: <xsl:element name="{factType}"> <xsl:copy-of select="document('')/*/namespace::ia" /> <xsl:attribute name="xsi:schemaLocation"> <xsl:text>http://www.orincon.com/ia </xsl:text> <xsl:value-of select="factType" /> </xsl:attribute> ... </xsl:element> You might want to use the *value* of the namespace to find the relevant namespace node instead, i.e.: <xsl:element name="{factType}"> <xsl:copy-of select="namespace::*[. = 'http://www.orincon.com/ia']" /> <xsl:attribute name="xsi:schemaLocation"> <xsl:text>http://www.orincon.com/ia </xsl:text> <xsl:value-of select="factType" /> </xsl:attribute> ... </xsl:element> It depends on whether and where you're ever going to change the prefix that's used with that namespace. I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] xpath expression in <xsl:styl, astockley | Thread | RE: [xsl] xpath expression in <xsl:, Sullivan, Dan |
[xsl] [Zvon] XML Cover Pages + W3C , Miloslav Nic | Date | RE: [xsl] FW: Toggling radio button, Elisabeth Kaminski |
Month |