[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: HELP, Validate generated XML file to a new XML sch

Subject: RE: HELP, Validate generated XML file to a new XML schema in XSL
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 5 May 2005 11:19:20 +0100
xsi schemalocation file
XSLT 2.0 allows you to specify the validation of the generated XML file to
be done as an intrinsic part of the transformation. The advantage of this is
that the validation is done earlier (and it's done automatically). Often
it's possible to detect errors at the time the stylesheet is compiled,
before you even run it against a source document; and where the errors are
detected at run-time, you can get error messages that point to the line of
code in the stylesheet that generated the bad output, rather than having to
study the output of the schema processor which only tells you where the
output itself is wrong. Try it out with Saxon-SA.

However, going back to your approach: Looking at your input and output, what
you seem to be doing is a near-identity transform that changes the value of
one attribute. There's a standard pattern for that:

<xsl:template match="node()|@*">
 <xsl:copy>
 <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
</xsl:template>

<xsl:template match="@xsi:schemaLocation" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <xsl:attribute name="xsi:schemaLocation">
    <xsl:text>http://www.xml.com/xml/unit newUnit.xsd</xsl:text>
  </xsl:attribute>
</xsl:template>

Again, however, I'd question the design. Most schema processors allow you to
say "validate document X against schema Y" - the location of the schema
doesn't have to be hard-coded in the xsi:schemaLocation attribute. Modifying
the document to change the xsi:schemaLocation attribute should therefore be
quite unnecessary.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Seng Kiat Lim [mailto:limsengkiat83@xxxxxxxxxxx] 
> Sent: 05 May 2005 09:08
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  HELP, Validate generated XML file to a new XML 
> schema in XSL 
> 
> XML document
> <?xml version="1.0"?>
> 
> <Unit xmlns="http://www.xml.com/xml/unit"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.xml.com/xml/unit unit.xsd">
> <Units>
> <Unit_Code>5555</Unit_Code>
> <Unit_Name>System</Unit_Name>
> </Units>
> </Unit>
> 
> XSL Stylesheet
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:unit="http://www.monash.edu.au/xml/unitManagement" >
> <xsl:output method="xml"/>
> <xsl:template match="/">
> <xsl:element name="Unit_Planning" xmlns="http://www.xml.com/xml/unit"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.xml.com/xml/unit newUnit.xsd">
> <xsl:for-each select="unit:Unit/unit:Units">
> <xsl:element name="Unit">
> <xsl:element name="Unit_Code">
> <xsl:value-of select="unit:Unit_Code"/>
> </xsl:element>
> <xsl:element name="Unit_Name">
> <xsl:value-of select="unit:Unit_Name"/>
> </xsl:element>
> </xsl:element>
> </xsl:for-each>
> </xsl:template>
> </xsl:stylesheet>
> 
> I wish to display XML that will validate to a new XML schema file.
> Hope to display XML
> <?xml version="1.0"?>
> <Unit xmlns="http://www.xml.com/xml/unit"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.xml.com/xml/unit newUnit.xsd">
> <Units>
> <Unit_Code>5555</Unit_Code>
> <Unit_Name>System</Unit_Name>
> </Units>
> </Unit>
> 
> Can anyone out there pls help me out? I fail to display the 
> exactly what I 
> want. I need to validate to a new schema from what I create. 
> It still be 
> generate the XML file but do not include any of the 
> schemalocation details 
> in the root element.
> Can anyone show me how to do it in XSL? I wish to know a way 
> to validate to 
> a new schema and show all the details.
> Thanks

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.