Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 14th, 2009, 09:35 AM
Registered User
 
Join Date: Aug 2009
Posts: 6
Thanks: 6
Thanked 0 Times in 0 Posts
Default parse multiple .XSD files with XSLT

Hi!
I have a problem with solving this problem,
i have 5 XSD Files (SCHEMA) where i want to get all <documentation> elements from and write them in one new XML File.
How can i do that ?
My problem is that i dont have any XML file which initialises the XSLT File...
 
Old August 14th, 2009, 10:08 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

With XSLT 2.0 you can run a named template as the initial template:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  version="2.0">

  <xsl:template name="main">
     <root>
       <xsl:copy-of select="(document('schema1.xsd'), document('schema2.xsd'), document('schema3.xsd'), document('schema4.xsd'), document('schema5.xsd'))//xs:documentation"/>
     </root>
   </xsl:template>

</xsl:stylesheet>
You can then run your stylesheet with your XSLT processor and designate the template with name 'main' as the initial template, for instance with option -it:main for Saxon and its command line usage.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
chaostimmy (August 17th, 2009)
 
Old August 15th, 2009, 06:48 AM
Registered User
 
Join Date: Aug 2009
Posts: 6
Thanks: 6
Thanked 0 Times in 0 Posts
Default

okay so far ive already been,
i did it with <xslt:variable name="file" select="doc('schema.xsd')">

i dont understand how to run that XSLT without an real input XML ...
In my Browser he needs an XML for it,
and Eclipse Oxygen parser wants an XML to...
 
Old August 15th, 2009, 07:28 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

As I said, with XSLT 2.0 you do not need a primary input document, you can instead define a named template and start processing with that named template.
With Saxon there is a command line option -it:templatename you can use, with AltovaXML tools you can use a command line option /n templatename so for the stylesheet I posted you would use e.g.
altova.exe /xslt2 sheet.xsl /n main
with Saxon something like
java -jar dir/saxon9.jar -xsl:sheet.xsl -it:main

I am not familiar with Eclipse or Oxygen, ask in a forum dedicated to that software if you don't find a setting yourself.


If you use XSLT 1.0 then you do not have that option, in that case you either need to provide a dummy XML input or you can choose one of the schema documents as the primary input document.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
chaostimmy (August 17th, 2009)
 
Old August 15th, 2009, 07:36 AM
Registered User
 
Join Date: Aug 2009
Posts: 6
Thanks: 6
Thanked 0 Times in 0 Posts
Default

ah okay now i know what youre talking about! BiG THANXXX
 
Old August 17th, 2009, 08:24 AM
Registered User
 
Join Date: Aug 2009
Posts: 6
Thanks: 6
Thanked 0 Times in 0 Posts
Default

i tried it with <xsl:copy-of select="doc('filename.xsd')//documentation"/>
but it won't work ...

<xsl:copy-of select="doc('filename.xsd')//text()"/> does work....

whhhyyy ??
 
Old August 17th, 2009, 08:28 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well the elements are in the namespace http://www.w3.org/2001/XMLSchema so bind a prefix to that namespace and use the prefix, as I did in my sample:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  version="2.0">

  <xsl:template name="main">
     <root>
       <xsl:copy-of select="(document('schema1.xsd'), document('schema2.xsd'), document('schema3.xsd'), document('schema4.xsd'), document('schema5.xsd'))//xs:documentation"/>
     </root>
   </xsl:template>

</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
chaostimmy (August 17th, 2009)
 
Old August 17th, 2009, 08:32 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Martin wrote ...//xs:documentation, so why did you expect ...//documentation to work? The element is in a namespace, so like all elements in a namespace, the name must be prefixed in an XPath expression.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
chaostimmy (August 17th, 2009)
 
Old August 17th, 2009, 09:58 AM
Registered User
 
Join Date: Aug 2009
Posts: 6
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Okay, seems like i didnt understand that basic thing.. i hopefully do now!

first i had this Namespace:
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.w3.org/2001/XMLSchema"
    version="2.0">
so i thought //documentation shall work ..

now i use
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.w3.org/2001/XMLSchema"
    version="2.0">
so i dont have to mark all xml elements with "xs:", right?
any other suggestions for it ?? Or is there an error in reasoning again ?

here is now my working "make documentation xml" xslt code:
Code:
<xsl:template match="filelist">
                <documentations>
                    <xsl:for-each select="file">
                        <xsl:if test="doc-available(text())">
                            <xsl:variable name="data" select="doc(text())"/>
                            <xsl:for-each select="$data//node()/@name">
                                    <documentation>
                                        <name><xsl:value-of select="."/></name>
                                        <text><xsl:value-of select="parent::node()[//xs:documentation]"/></text>
                                    </documentation>
                            </xsl:for-each>
                        </xsl:if>
                    </xsl:for-each>
                </documentations>
</xsl:template>
with the input XML:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="create_doc_XML.xsl" ?>
<filelist>
    <file>sourceData.xsd</file>
    <file>test-cases.xsd</file>
    <file>uoms.xsd</file>
</filelist>
i thought taking this xml with filenames would be a good way to make this program more dynamic..

now JUDGEMENT plz

by the way you guys are GREAT! big THANX

Last edited by chaostimmy; August 17th, 2009 at 10:01 AM..
 
Old August 17th, 2009, 10:02 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

No, the default namespace in the stylesheet does not apply to unprefixed names in XPath expressions.

You can set a default namespaces for such names in XSLT 2.0 using the default-xpath-namespace attribute.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
chaostimmy (August 17th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt and xsd leonid XSLT 1 August 17th, 2006 09:02 AM
XSLT to make multiple hyperlinked HTML files dai.hop XSLT 1 January 11th, 2006 03:05 PM
Merging XSD files in one XSD file by using what? haoxuqian XML 1 November 4th, 2005 01:42 PM
Validating Xml files with XSD file ShaileshShinde VB.NET 2002/2003 Basics 1 September 12th, 2005 07:00 AM
Transform .xsd files to a .xml file lxu XSLT 0 July 19th, 2004 09:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.