473,396 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

help with element deletion using xslt

Hi,

I have a software generated schema which creates a few empty elements,
e.g. <xsd:sequence/>. I would like to be able to delete these elements
from the schema post-generation using XSLT.

I've tried using the identity pattern to copy the whole schema except
these rogue elements but I seem to be getting stuck on how to
correctly choose this particular 'sequence' element to ignore during
copying.

I would really appreciate some pointers on how I could do this.

regards,

Wideboy
Jun 27 '08 #1
3 2470

WideBoy <na**********@gmail.comwrote in
<07**********************************@a22g2000hsc. googlegroups.com>:
I have a software generated schema which creates a few
empty elements, e.g. <xsd:sequence/>. I would like to be
able to delete these elements from the schema
post-generation using XSLT.

I've tried using the identity pattern to copy the whole
schema except these rogue elements but I seem to be
getting stuck on how to correctly choose this particular
'sequence' element to ignore during copying.
Assuming you've bound the XML Schema namespace to the xsd
prefix in your transformation:

xsd:sequence[not(*)]

--
I'm not dead, just pinin' for the fnords.
Jun 27 '08 #2
On Apr 16, 11:21 am, Pavel Lepin <p.le...@ctncorp.comwrote:
WideBoy <naran.hir...@gmail.comwrote in
<07d5825c-dd29-453b-ba66-121c486bd...@a22g2000hsc.googlegroups.com>:
I have a software generated schema which creates a few
empty elements, e.g. <xsd:sequence/>. I would like to be
able to delete these elements from the schema
post-generation using XSLT.
I've tried using the identity pattern to copy the whole
schema except these rogue elements but I seem to be
getting stuck on how to correctly choose this particular
'sequence' element to ignore during copying.

Assuming you've bound the XML Schema namespace to the xsd
prefix in your transformation:

xsd:sequence[not(*)]

--
I'm not dead, just pinin' for the fnords.
Pavel,

Thanks for your advice, unfortunately, being a total novice it did not
work for me.

Here's my input test schema and xslt that I'm using.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="TestSchema">
<xsd:annotation>
<xsd:documentation>Comment describing your root element</
xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:complexType name="VarCharStructure">
<xsd:annotation>
<xsd:documentation>A characteristic that can vary over time. The
time at which the characteristic is recorded is given by the activity
or occurrence of information to which it is linked.</
xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="SuperClassStructure">
<xsd:sequence/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="SuperClassStructure">
<xsd:annotation>
<xsd:documentation>Provides a referencable ID element for all class
objects</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="SuperClassURN" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

Processed using this XSLT:
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/
>
<!-- copy through any comments or processing instructions found in
the input schema -->
<xsl:template match="comment()|processing-instruction()">
<xsl:copy/>
</xsl:template>
<!-- copy any other elements and associated attributes and values -->
<xsl:template match="*">
<xsl:if test=".//xsd:sequence[not(*)]"/>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

Produces the same output as the input demonstrating my total lack of
understanding of xslt.

best regards,

W.
Jun 27 '08 #3
WideBoy wrote:
Produces the same output as the input demonstrating my total lack of
understanding of xslt.
You simply need

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xsl:template match="xs:sequence[not(node())]"/>

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

</xsl:stylesheet>

The second template above is the identity transformation template, the
first template ensures that empty xs:sequence elements are not copied.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
1
by: Miguel J. Jiménez | last post by:
Hi, I'm using OpenCMS and XML/XSLT to produce pages... The structure OpenCMS use for internal pages is something like this: <]> The desired effect I want to get is a page with "A title" in...
1
by: CB | last post by:
I am using xerces 2.5.0 and xalan 2.6.0, and am following the xinclude instructions on the xerces faq at http://xml.apache.org/xerces2-j/faq-xinclude.html, and I am having no luck. I imagine I...
5
by: dennis | last post by:
Hi, First of all, hi to you all. I'm working on a Delphi project wich is becoming near it's deadline. I have a very simple XSLT question wich i hope one of you folks can help me with? The...
9
by: AA | last post by:
Hello, I need to extract an element from a xml document something like this <myXml> <Header> <Name/> <LastName/> <Age/> </Head> <Body> <Properties>
5
by: nospam | last post by:
I'm trying to transform an xml file that contains empty short elements like the following: <element attrib="abc"/> using the XmlTransform class. But I cannot seem to preserve the short format...
4
by: ina | last post by:
Hello all, I am newbie in xml and have a problem with this parse. I have this xml.file <Style> <Strategy>
2
by: shapper | last post by:
Hello, I am for days trying to apply a XSL transformation to a XML file and display the result in a the browser. I am using Asp.Net 2.0. Please, could someone post just a simple code example,...
4
by: n.phelge | last post by:
I need to perform an XSLT to set the namespace on some XML and I need to preserve the original document line formatting to assist with error handling (so the line number from any schema validation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.