473,804 Members | 3,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2501

WideBoy <na**********@g mail.comwrote in
<07************ *************** *******@a22g200 0hsc.googlegrou ps.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...@ctncor p.comwrote:
WideBoy <naran.hir...@g mail.comwrote in
<07d5825c-dd29-453b-ba66-121c486bd...@a2 2g2000hsc.googl egroups.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"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xsd:element name="TestSchem a">
<xsd:annotation >
<xsd:documentat ion>Comment describing your root element</
xsd:documentati on>
</xsd:annotation>
</xsd:element>
<xsd:complexTyp e name="VarCharSt ructure">
<xsd:annotation >
<xsd:documentat ion>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:documentati on>
</xsd:annotation>
<xsd:complexCon tent>
<xsd:extensio n base="SuperClas sStructure">
<xsd:sequence/>
</xsd:extension>
</xsd:complexCont ent>
</xsd:complexType >
<xsd:complexTyp e name="SuperClas sStructure">
<xsd:annotation >
<xsd:documentat ion>Provides a referencable ID element for all class
objects</xsd:documentati on>
</xsd:annotation>
<xsd:sequence >
<xsd:element name="SuperClas sURN" 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:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xsl:template match="xs:seque nce[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
2750
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 straight XML file http://www.discovertravelandtours.com/test/templates/test.xml?Location=Germany To another XML file http://www.discovertravelandtours.com/test/templates/test2.xml?Location=Germany
1
4976
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 bold letters, so I use the following XSL: <xsl:copy-of select="/root/title"/>
1
1755
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 must be missing something fundamental, can someone point it out, please? Here are all the gory details; ---- command line ----
5
1467
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 problem is i need to transform a xml file from this: <root>
9
4350
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
1431
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 as everytime it get's converted to the longer format of: <element attrib="abc"></element>
4
1683
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
1975
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, either C# or VB.NET, that I can try. Thank You Very Much,
4
3128
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 error matches the original line number). The original XML looks like this: <Head> <Body Val1="10" Val2="11" /> </Head>
0
9587
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10324
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.