Subject: [xsl] xpath expression in <xsl:stylesheet> element From: astockley@xxxxxxxxxxx Date: Fri, 24 Aug 2001 10:05:07 -0700 |
I am trying to create a generic stylesheet for a number of different input.xml. Each input.xml has a different factType which in turn has its own schema whose location and name I want to specify in the output. (For Example ideally I want the output root element to be <LoginHypothesis xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:ia="http://www.orincon.com/ia" xsi:schemaLocation= "http://www.orincon.com/ia LoginHypothesis.xsd">) I would also like to automatically get the name of the schema from the incoming document as opposed to having it hard coded in the stylesheet. 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. Any suggestions on how I handle this gratefully received. Thank you Annie This is what I have at the moment input.xml <ia:unorderedFact xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:schemaLocation="http://www.orincon.com/ia UnorderedFact.xsd" xmlns:ia="http://www.orincon.com/ia"> <factType>LoginHypothesis</factType> <slot> <tag>userName</tag> <ia:userName>jpublic</ia:userName> </slot> <slot> <tag>hostName</tag> <ia:hostName>linux1</ia:hostName> </slot> ... </ia:unorderedFact> stylesheet.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform" xmlns:ia="http://www.orincon.com/ia" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"> <xsl:output method="xml" indent="yes"/> <xsl:template match="ia:unorderedFact"> <xsl:element name="{child::factType/text()}"> <xsl:text/> <xsl:for-each select="//slot"> <xsl:choose> <xsl:when test="count(child::*)=2"> <xsl:element name="{child::tag/text()}"> <xsl:value-of select="./*[position()=2]"/> </xsl:element> <xsl:text/> </xsl:when> <xsl:when test="count(child::*)>2"> ...... </xsl:stylesheet> output.xml <?xml version="1.0" encoding="UTF-8"?> <LoginHypothesis xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:ia="http://www.orincon.com/ia"> <userName>jpublic</userName> <hostName>linux1</hostName> .... </LoginHypothesis> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Colon in entity reference, Wendell Piez | Thread | Re: [xsl] xpath expression in <xsl:, Jeni Tennison |
Re: [xsl] FW: Toggling radio button, Jeni Tennison | Date | [xsl] [Zvon] XML Cover Pages + W3C , Miloslav Nic |
Month |