help with element deletion using xslt

Discussion in 'XML' started by WideBoy, Apr 16, 2008.

  1. WideBoy

    WideBoy Guest

    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
     
    WideBoy, Apr 16, 2008
    #1
    1. Advertising

  2. WideBoy

    Pavel Lepin Guest

    WideBoy <> wrote in
    <>:
    > 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 Lepin, Apr 16, 2008
    #2
    1. Advertising

  3. WideBoy

    WideBoy Guest

    On Apr 16, 11:21 am, Pavel Lepin <> wrote:
    > WideBoy <> wrote in
    > <>:
    >
    > > 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:eek:utput 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.
     
    WideBoy, Apr 16, 2008
    #3
  4. 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/
     
    Martin Honnen, Apr 16, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ME
    Replies:
    0
    Views:
    384
  2. Anonymous
    Replies:
    5
    Views:
    322
    Gianni Mariani
    Aug 31, 2007
  3. HANM
    Replies:
    2
    Views:
    723
    Joseph Kesselman
    Jan 29, 2008
  4. ME

    Data Deletion Using the ObjectDataSource Control

    ME, Jan 12, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    125
  5. ME

    Data Deletion Using the ObjectDataSource Control

    ME, Jan 12, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    105
Loading...

Share This Page