XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Remove leading Zeros from a st... (4)
-> + how to parse a html element fo... (2)
-> + Add namespaces to target messa... (2)
-> + XSLT Transformation - insertin... (3)
-> + Convert binary xml (9)
-> + XSLT Transformation (4)
-> + Generating hyperlinks (3)
-> + XSLT to PDF problem (with JAVA... (2)
-> + how to add onclick_ with try/c... (2)
-> + Keep table in one page. xsl-fo... (4)
-> + Cannot find a matching 2-argum... (3)
-> + Creating one string from a sub... (2)
-> + XSLT: Traversing XML twice for... (6)
-> + Copy element without namespace... (5)
-> + Create dynamic elemant name (2)
-> + XSLT: Traversing XML twice for... (3)
-> + Problem including Javascript (2)
-> + Looping through attributes (4)
-> + Transform values into elements... (4)
-> + Problem with deep node copy an... (2)
-> + Comparing Dates With ASP.NET 2... (3)
-> + Converting tree structure to h... (4)
-> + Attributes to element transfor... (2)
-> + XSLT transformation (2)
-> + XSLT transformation (5)
-> + xsl:character-map not working (2)
-> + Removing duplicates entries. (2)
-> + Image issues. (2)
-> + xsl transformation (4)
-> + XSL Question (5)
-> + how to insert xml file as an n... (2)
-> + Document Function (2)
-> + convert seconds to hh:mm:ss (5)
-> + how to remove attribute while ... (3)
-> + XSL-FO question (2)
-> + EDI 997 creation. (7)
-> + Line break within a tag in XML... (2)
-> + Contact Help Needed (2)
-> + ACK 997 (2)
-> + XSLT to output XML( which conf... (11)
-> + Retrieving all nodes where a c... (6)
-> + Verifying XML and XSD within X... (4)
-> + How to validate date format in... (3)
-> + XSLT question (2)
-> + Muenchian grouping (2)
-> + How to remove specific text en... (8)
-> + If Else Condition along with L... (2)
-> + SAXON Problem (2)
-> + comapring global variable valu... (2)
-> + copying the value of xsl in va... (2)
-> + Urgent:XSLT element value sel... (2)
-> + Ignoring first element using f... (2)
-> + EDI X12 to XML (4)
-> + XSLT FOR-EACH HELP (2)
-> + Sorting Help Needed (3)
-> + XSLT help with linking (2)
-> + selecting data into node set b... (2)
-> + Watch and Variable in Debug no... (4)
-> + Transforming XML to XML - grou... (2)
-> + Saxon 9.0 B support in debug m... (2)
-> + Repeating element question (2)
-> + Newly Purchased Version Not La... (2)
-> + xsl:include not finding file (5)
-> + JAXP and XSLT 2.0 / XPATH 2.0 (2)
-> + ASP:DropDownList trigger in Xs... (2)
-> + Auto-Skip empty values (2)
-> + retrieving a javascript functi... (2)
-> + need help (2)
-> + html tag ignored (2)
-> + Quick reply needed (8)
-> + xslt to remove namespaces but ... (2)
-> - Using a WSDL definition in an ... (1)
-> + XSL logic issue for simple inp... (6)
-> + Regarding XML namespace prefix... (4)
-> + Mapper reoganizes itself. (8)
-> + XSL Substring Removal (2)
-> + Regarding XSLT logic for a sim... (3)
-> + XSLT Transform documentation (2)
-> + XSLT stack trace in case of er... (3)
-> + No New Line (2)
-> - No New Line (1)
-> + howto loop through a sequence (2)
-> + xml and xsl and whitespace in... (2)
-> + XSL Date formatting (4)
-> + XSL to XSL Mapping using custo... (4)
-> + flat xml to nested xml comvers... (4)
-> + Including schema in scenario (2)
-> + DTDs and traversing (2)
-> + Help with transformation (2)
-> + Problem running XSLT against X... (2)
-> + Carriage return in the output (5)
-> + Generating XSLT to match a sch... (3)
-> + WYSIWYG editor (2)
-> + Grouping without For-Each (3)
-> + output XML using XSLT (8)
-> + Help configuring Xalan-j proce... (8)
-> + Convert Existing HTML pages to... (2)
-> + Generating Transformation - XS... (4)
-> + DOCTYPE public and system info... (2)
-> + Using EXSLT str:tokenize funct... (5)
-- Previous [661-680] [681-700] [701-720] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Matthew FadoulSubject: How can I make a subset Schema (XSD) using XSL/XQuery in Stylus Studio?
Author: Matthew Fadoul
Date: 01 Oct 2007 05:02 PM
Hello, I'm a new Stylus Studio user, and a bit of an XSL/Xquery newbie, too. Sorry in advance for the simple question...

Anyway, I've got a very large schema file that is killing the JAXB code generator, and I thought that I might use Stylus Studio to shrink down my schema so that I have a more manageable subset schema for code gen, validation, etc.

Note: I could probably edit the XSD file directly, but I wanted a process that was repeatable.

The basic technique I wanted to use was to take any xs:elements whose "name" attibute matched a set of elements that were of interest to me. I would also like to preserve ancestor and descendant nodes.

Using a simple example, let's say I want to preserve "Element-1" and "Element-2" in the following XML schema file:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Element-1">
<xsd:complexType>
<xsd:sequence id="01">
<xsd:element name="ID" type="xsd:integer" default="0"/>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Element-2">
<xsd:complexType>
<xsd:sequence id="02">
<xsd:element name="ID" type="xsd:integer" default="0"/>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Address">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="First Name" type="xsd:string"/>
<xsd:element name="Last Name" type="xsd:string"/>
<xsd:element name="House Number" type="xsd:string"/>
<xsd:element name="Street" type="xsd:string"/>
<xsd:element name="City" type="xsd:string"/>
<xsd:element name="State" type="xsd:string"/>
<xsd:element name="ZIP" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="First Name"/>

<!-- The schema goes on and on and on... -->
</xsd:schema>

The result I'm hoping for is:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Element-1">
<xsd:complexType>
<xsd:sequence id="01">
<xsd:element name="ID" type="xsd:integer" default="0"/>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Element-2">
<xsd:complexType>
<xsd:sequence id="02">
<xsd:element name="ID" type="xsd:integer" default="0"/>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

Basically, I think that XSL and Xquery is the way to go. I know some of the basics (e.g. matching [@name='Element-1'] and using filters like ancestor-or-self and descendant), but I'm having a bit of trouble putting them all together.

Any ideas?

An "advanced" question that isn't as important, but may be interesting:

After figuring out the above, is there a way to parameterize this functionality? For example, if I'd like to make a subset schema with 10-20 different elements, is there a way of encapsulating the "template" command instead of copying it 10-20 times and making the string substitution?

Postnext
James DurningSubject: How can I make a subset Schema (XSD) using XSL/XQuery in Stylus Studio?
Author: James Durning
Date: 02 Oct 2007 03:33 PM
I would suggest something like the following:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="internal">
<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="xs:element">
<xsl:if test="@name = document('')//my:names/name">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>
<my:names>
<name>Element-1</name>
<name>Element-2</name>
</my:names>
</xsl:stylesheet>

Notice the list of element names at the end.
The elements that match the list are copied, whereas those that do not are not.

Postnext
Matthew FadoulSubject: How can I make a subset Schema (XSD) using XSL/XQuery in Stylus Studio?
Author: Matthew Fadoul
Date: 03 Oct 2007 05:00 PM
Hello James,

Thank you for your example code. I've made some tweaks, and here's where I'm currently at:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- Looking at immediate children of the root node. -->
<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<!-- Prototype Template -->
<xsl:template name="MySimpleTemplate">
<xsl:copy-of select="."/>
</xsl:template>

<!-- Using the Prototype Template -->
<!-- I had to explicitly match each of these nodes. -->
<xsl:template match="xs:element[@name='Element-1']">
<xsl:call-template name="MySimpleTemplate"/>
</xsl:template>

<xsl:template match="xs:element[@name='Element-2']">
<xsl:call-template name="MySimpleTemplate"/>
</xsl:template>

<!-- Added this template to remove some whitespace. -->
<xsl:template match="node()"/>
</xsl:stylesheet>

Some comments:

1) Encapsulated Templates

I mentioned this at the end of my original post. I was looking for named templates, which I use above.

2) <my:names> Data Structure

I thought this was a clever solution; but, I couldn't get it to work on my machine. The XSL couldn't seem to find the "my:names" node. I was thinking that the code (as written) might not automatically iterate through the list of names...maybe I'm wrong, though. Maybe an "xsl:for-each" element would be appropriate, if I could figure out how to access the "my:names" node.

3) XPath Axes

The current solution relies on the templates to search the immediate children of the root node. Unfortunately, I'm also looking for nodes that are deeper in the hierarchy. In particular, I'd like to find and preserve at some reference elements (e.g. <xs:element ref="Element-1"/>). I wanted to use axes such as "ancestor" and "descendant" to get to these nodes, while preserving the rest of the hierarchy. Basically, I want to preserve any node that is an ancestor or descendant or itself one of the nodes I specify. There is a hard code workaround I can try to get to most of the reference nodes, but I was hoping that the XPath Axes could provide an elegant solution.

4) XSL Mapper Error.

When I click on the "mapper" pane for the XSL file, I get the error, "Mapper data population failed." I did a Google search, and apparently this can happen when the XSL uses multiple namespaces. Any further advice to work around this?

5) White Space.

I added the last template to remove some of the whitespace. It actually is a bit overkill (removing more than I'd like), but Stylus Studio's auto-format button gives me an easy solution.

I've got a pretty bad case of new-useritis, so I appreciate all the help from the forum community!

Postnext
(Deleted User) Subject: How can I make a subset Schema (XSD) using XSL/XQuery in Stylus Studio?
Author: (Deleted User)
Date: 05 Oct 2007 12:08 PM
Hi Matthew,
the "Data population failed" error is a generic error, shown when Mapper fails to parse the XPath expressions in the XSL. However, I could not reproduce it using the fragments you posted. Could you post the code that triggers this error?

Thanks,
Alberto

Posttop
Matthew FadoulSubject: How can I make a subset Schema (XSD) using XSL/XQuery in Stylus Studio?
Author: Matthew Fadoul
Date: 09 Oct 2007 08:32 PM
Just a little update. When started from scratch and tried to recreate the Mapper error, Stylus Studio didn't complain when I clicked on the Mapper tab. So no more problem with the Mapper tab. :)

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.