help with element deletion using xslt

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WideBoy

    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
  • Pavel Lepin

    #2
    Re: help with element deletion using xslt


    WideBoy <naran.hirani@g mail.comwrote in
    <07d5825c-dd29-453b-ba66-121c486bdee4@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.

    Comment

    • WideBoy

      #3
      Re: help with element deletion using xslt

      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.

      Comment

      • Martin Honnen

        #4
        Re: help with element deletion using xslt

        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

        Comment

        Working...