XSLT for WSDL reduction

Discussion in 'XML' started by Scott Sauyet, May 24, 2007.

  1. Scott Sauyet

    Scott Sauyet Guest

    I'm trying to select a subset of a WSDL document using XSLT and a
    simple text document describing the high-level elements to include. I
    have it working fine for selecting the services, bindings, portTypes,
    and messages to use. But I'm stumped on how to get the xs:simpleType
    and xs:complexType elements filtered properly. I am not trying to do
    this in a generic way. The WSDL is generated by a tool in our backend
    system, and I know a fair bit about its structure, although I have no
    control over it.

    I am neither a novice nor an expert with XSLT. I don't use it much,
    though, and I'm sure it shows. Any advice would be appreciated. If I
    have to resort to doing this in code, I will, but I thought XSLT would
    be up to the job...

    I posted a sample WSDL with only one high-level service in it. It
    represents both the input and the expected output format:

    http://scott.sauyet.com/issues/2007-05-24/temp.wsdl


    I import the text file (a whitespace separated list of service names)
    and store it in a string simply by

    <!DOCTYPE xsl:stylesheet [
    <!ENTITY service-list SYSTEM "services.txt">
    ]>

    <xsl:variable name="list">
    <xsl:call-template name="normalize">
    <xsl:with-param name="data">&service-list;</xsl:with-
    param>
    </xsl:call-template>
    </xsl:variable>

    <xsl:template name="normalize">
    <xsl:param name="data" />
    <xsl:value-of select="concat(normalize-space($data), ' ')" />
    </xsl:template>

    And I use a similar technique to define "service-list", which is the
    same list with "Service" appended to each name.

    Inside my main template, I can then use this to define the services to
    choose:

    <xsl:for-each select="wsdl:service">
    <xsl:if test="contains($service-list, @name)">
    <xsl:copy-of select="."/>
    </xsl:if>
    </xsl:for-each>

    And I can select portTypes just as simply:

    <xsl:for-each select="wsdl:portType">
    <xsl:if test="contains($list, @name)">
    <xsl:copy-of select="."/>
    </xsl:if>
    </xsl:for-each>

    Bindings are slightly more complex:

    <xsl:for-each select="wsdl:binding">
    <xsl:variable name="bindName" select="concat('tns:', @name)"/>
    <xsl:if test="count(../wsdl:service/wsdl:port[@binding=
    $bindName and contains($service-list, ../@name)]) > 0">
    <xsl:copy-of select="."/>
    </xsl:if>
    </xsl:for-each>

    And messages are getting scary:

    <xsl:for-each select="wsdl:message">
    <xsl:variable name="messName" select="concat('tns:', @name)"/>
    <xsl:if test="count(../wsdl:portType/wsdl:eek:peration/
    wsdl:input[@message=$messName and contains($list, ../../@name)] | ../
    wsdl:portType/wsdl:eek:peration/wsdl:eek:utput[@message=$messName and
    contains($list, ../../@name)]) > 0">
    <xsl:copy-of select="."/>
    </xsl:if>
    </xsl:for-each>

    But I can't really figure out any way to get to, say, the complexTypes
    required. What I want, in essence, is to display a complex type C
    if there is a message M with a part P where P/@type = C.name and there
    exists a portType T with an operation O with an input I where I/
    @message = M/@name. (And this is a simplification?!) But I can't see
    how to express that in XPath.

    Any suggestions?

    Thanks,

    -- Scott Sauyet
     
    Scott Sauyet, May 24, 2007
    #1
    1. Advertising

  2. Scott Sauyet

    Ixa Guest

    > But I can't really figure out any way to get to, say, the complexTypes
    > required.


    Just use the same method as with others: XPath predicates for
    appropriate elements.

    > to display a complex type C


    So, use normal XPath to get those elements and store name to variable.

    ---8<---8<---
    <xsl:for-each select="/wsdl:definitions/wsdl:types/xs:schema/xs:complexType">
    <xsl:variable name="C.name" select="concat('ro:', @name)"/>
    ---8<---8<---

    > if there is a message M with a part P where P/@type = C.name and there
    > exists a portType T with an operation O with an input I where
    > I/@message = M/@name


    Use two predicates:

    * verify that there is a message that has the same name
    * verify that there is an equal message elsewhere

    ---8<---8<---
    <xsl:if test="/wsdl:definitions/wsdl:message[wsdl:part/@type =
    $C.name][concat('tns:', @name) =
    /wsdl:definitions/wsdl:portType/wsdl:eek:peration/wsdl:input/@message]">
    ---8<---8<---

    --
    Ixa
     
    Ixa, May 26, 2007
    #2
    1. Advertising

  3. Scott Sauyet

    Scott Sauyet Guest

    On May 26, 2:09 am, Ixa <> wrote:
    > <xsl:for-each select="/wsdl:definitions/wsdl:types/xs:schema/xs:complexType">
    > <xsl:variable name="C.name" select="concat('ro:', @name)"/>
    >
    > > if there is a message M with a part P where P/@type = C.name and there
    > > exists a portType T with an operation O with an input I where
    > > I/@message = M/@name

    >
    > Use two predicates:
    >
    > * verify that there is a message that has the same name
    > * verify that there is an equal message elsewhere


    I just noted that my very long response to this from earlier in the
    week managed to disappear.

    Thank you for your help, Ixa. I did settle on a different solutions,
    but I learned some techniques from yours.

    -- Scott
     
    Scott Sauyet, May 31, 2007
    #3
    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. Patrick

    Bus reduction

    Patrick, Jun 7, 2004, in forum: VHDL
    Replies:
    1
    Views:
    576
    Egbert Molenkamp
    Jun 7, 2004
  2. Bryan Galvin

    NodeSet Reduction

    Bryan Galvin, Jun 9, 2004, in forum: XML
    Replies:
    3
    Views:
    443
    Bryan Galvin
    Jun 14, 2004
  3. Bryan Galvin
    Replies:
    2
    Views:
    446
    Bryan Galvin
    Sep 29, 2004
  4. A B Carter

    efficient list reduction

    A B Carter, May 11, 2004, in forum: Python
    Replies:
    2
    Views:
    570
    Paul Rubin
    May 11, 2004
  5. ago
    Replies:
    11
    Views:
    710
    Anton Vredegoor
    Jan 20, 2006
Loading...

Share This Page