Hi Tim,
You would need to use Schema Aware XSLT
processor(and therefore XSLT 2.0). Saxon 8.1 supports
this feature..
Regards,
Mukul
--- tim(_at_)reatech(_dot_)com wrote:
Hello,
I am trying to apply an XSL stylesheet to an XML
file that uses a schema.
I will discuss first what does work.
The following is the input XML file (XML1):
<?xml version="1.0" encoding="UTF-8" ?>
<!-- MainComment1 -->
<mainelement>
<!-- SubComment1.1 -->
<subelement name="sub1">content</subelement>
<!-- SubComment1.2 -->
<!-- SubComment2.1 -->
<subelement name="sub2">content</subelement>
<!-- SubComment2.2 -->
</mainelement>
<!-- MainComment2 -->
The following is the xsl I have so far (XSL1):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.1" indent="yes"
/>
<xsl:template match="comment()">
<xsl:comment><xsl:value-of
select="."/></xsl:comment>
</xsl:template>
<xsl:template match="subelement|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="mainelement|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:comment >NewSubComment1.1</xsl:comment>
<xsl:text>
</xsl:text>
<subelement name="newsub">content</subelement>
<xsl:comment >NewSubComment1.2</xsl:comment>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The following is the output from applying XSL1 to
XML1 (OUTPUT1):
<?xml version="1.0" encoding="UTF-8"?>
<!-- MainComment1 -->
<mainelement>
<!-- SubComment1.1 -->
<subelement name="sub1">content</subelement>
<!-- SubComment1.2 -->
<!-- SubComment2.1 -->
<subelement name="sub2">content</subelement>
<!-- SubComment2.2 -->
<!--NewSubComment1.1-->
<subelement name="newsub">content</subelement>
<!--NewSubComment1.2-->
</mainelement>
<!-- MainComment2 -->
This is exactly what I want without the schema
(OUTPUT1). The problem is when
the XML file uses a schema which is my real world
problem.
The following is the input XML file that uses the
schema (XML2):
<?xml version="1.0" encoding="UTF-8" ?>
<!-- MainComment1 -->
<mainelement
xmlns="http://www.mydomain.com/mainelement"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mydomain.com/mainelement
file:///C:/schemas/mainelement.xsd">
<!-- SubComment1.1 -->
<subelement name="sub1">content</subelement>
<!-- SubComment1.2 -->
<!-- SubComment2.1 -->
<subelement name="sub2">content</subelement>
<!-- SubComment2.2 -->
</mainelement>
<!-- MainComment2 -->
When I apply XSL1 to XML2 I get the following output
(OUTPUT2):
<?xml version="1.0" encoding="UTF-8"?>
<!-- MainComment1 -->
<!-- SubComment1.1 -->
content
<!-- SubComment1.2 -->
<!-- SubComment2.1 -->
content
<!-- SubComment2.2 -->
<!-- MainComment2 -->
OUTPUT2 is clearly not what I want. I want the
exact same output as OUTPUT1
except with the schema location and xmlns etc. The
following is the desired
output (DESIREDOUTPUT):
<?xml version="1.0" encoding="UTF-8"?>
<!-- MainComment1 -->
<mainelement
xmlns="http://www.mydomain.com/mainelement"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mydomain.com/mainelement
file:///C:/schemas/mainelement.xsd">
<!-- SubComment1.1 -->
<subelement name="sub1">content</subelement>
<!-- SubComment1.2 -->
<!-- SubComment2.1 -->
<subelement name="sub2">content</subelement>
<!-- SubComment2.2 -->
<!--NewSubComment1.1-->
<subelement name="newsub">content</subelement>
<!--NewSubComment1.2-->
</mainelement>
<!-- MainComment2 -->
Can anyone help me understand how to modify my XSL1
to create the DESIREDOUTPUT?
Any help would be greatly appreciated. I have been
trying to make this work
for days!
Thanks,
Tim
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--