[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Applying contains() to multiple nodes problem

Subject: Applying contains() to multiple nodes problem
From: "Ioannis Kanaris" <kanaris.i@xxxxxxxxx>
Date: Thu, 4 Oct 2007 15:37:41 +0300
 Applying contains() to multiple nodes problem
Hello to all,

I am working on XML to XML transformations and I have a problem
related to contains() function. I am providing the source XML, the
XSLT and target XML files below:

SOURCE XML

<pathway image="http://www.genome.jp/kegg/pathway/map/map00362.gif "
link="http://www.genome.jp/dbget-bin/show_pathway?map00362"
name="path:map00362"  number="00362" org="map" title="Benzoate
degradation via hydroxylation">

    <entry id="8" name= "ec:1.14.13.33" reaction="rn:R01296 rn:R01298"
type="enzyme" ></entry>
    <entry id="9" name= "ec:1.14.13.2" reaction="rn:R01296 rn:R01298"
type="enzyme" ></entry>
    <entry id="20" name= "cpd:C00156" type="compound"></entry >
    <entry id="21" name= "cpd:C00230" type="compound"></entry >
    <entry id="41" name= "ec:1.13.11.-" reaction="rn:R01629 rn:R01630"
type="enzyme" ></entry>
    <entry id="109" name= "cpd:C02814" type="compound"></entry >

    <reaction name="rn:R01296" type="reversible" >
        <substrate name="cpd:C00156"></substrate >
        <product name="cpd:C00230"></product >
    </reaction>
    <reaction name="rn:R01298" type="reversible" >
        <substrate name="cpd:C00156"></substrate >
        <product name="cpd:C00230"></product >
    </reaction>
    <reaction name="rn:R01629" type="irreversible" >
        <substrate name="cpd:C00230"></substrate >
        <product name="cpd:C02814"></product >
    </reaction>
    <reaction name="rn:R01630" type="irreversible" >
        <substrate name="cpd:C00230"></substrate >
        <product name="cpd:C02814"></product >
    </reaction>
</pathway>

XSLT FILE


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform "
version="1.0" xmlns:sbml="http://www.sbml.org/sbml/level2 "
xmlns="http://www.sbml.org/sbml/level2" xmlns:celldesigner=
"http://www.sbml.org/2001/ns/celldesigner">
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/>

    <xsl:template match="reaction">
        <xsl:if test="(boolean(substrate)) and (boolean(product))">
            <xsl:element name="reaction">
                <xsl:attribute name="id">
                    <xsl:value-of select="translate(@name,'rn:','')" />
                </xsl:attribute>
                <xsl:attribute name="name">
                    <xsl:value-of select="translate(@name,'rn:','')" />
                </xsl:attribute>
                <xsl:choose>
                    <xsl:when test="@type='reversible'">
                        <xsl:attribute name="reversible">true </xsl:attribute>
                    </xsl:when>
                    <xsl:when test="@type='irreversible'">
                        <xsl:attribute name="reversible">false </xsl:attribute>
                    </xsl:when>
                </xsl:choose>
                <xsl:element name="listOfReactants">
                    <xsl:for-each select="substrate">
                        <xsl:variable name="reac" select= "@name"/>
                        <xsl:call-template name="SearchCompound">
                            <xsl:with-param name="name" select= "$reac"/>
                        </xsl:call-template>
                    </xsl:for-each>
                </xsl:element>
                <xsl:element name="listOfProducts">
                    <xsl:for-each select="product">
                        <xsl:variable name="prod" select= "@name"/>
                        <xsl:call-template name="SearchCompound">
                            <xsl:with-param name="name" select= "$prod"/>
                        </xsl:call-template>
                    </xsl:for-each>
                </xsl:element>
                <xsl:variable name="rea" select= "@name"/>
                <xsl:choose>
                    <xsl:when test="//entry/@reaction=$rea">
                        <xsl:element name="listOfModifiers">
                            <xsl:call-template name="SearchModifier">
                                <xsl:with-param name="name" select= "$rea"/>
                            </xsl:call-template>
                        </xsl:element>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:if test="contains(//entry/@reaction, $rea)">
                            <xsl:element name="listOfModifiers">
                                <xsl:call-template name="SearchModifier">
                                    <xsl:with-param name="name" select= "$rea"/>
                                </xsl:call-template>
                            </xsl:element>
                        </xsl:if>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:element>
        </xsl:if>
    </xsl:template>

    <xsl:template name="SearchCompound">
        <xsl:param name="name"/>
        <xsl:for-each select="//entry">
            <xsl:variable name="entry" select= "@name"/>
            <xsl:choose>
                <xsl:when test="$entry=$name">
                    <xsl:element name="speciesReference">
                        <xsl:attribute name="species">
                            <xsl:value-of select="concat('s', @id)" />
                        </xsl:attribute>
                    </xsl:element>
                </xsl:when>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>

    <xsl:template name="SearchModifier">
        <xsl:param name="name"/>
        <xsl:for-each select="//entry">
            <xsl:variable name="act" select="@reaction" />
            <xsl:choose>
                <xsl:when test="contains($act,$name)">
                    <xsl:element name="modifierSpeciesReference">
                        <xsl:attribute name="species">
                            <xsl:value-of select="concat('s', @id)" />
                        </xsl:attribute>
                    </xsl:element>
                </xsl:when>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

TARGET XML

<reaction id="R01296" name= "R01296" reversible="true">
  <listOfReactants>
    <speciesReference species="s20"/>
  </listOfReactants>
  <listOfProducts>
    <speciesReference species="s21"/>
  </listOfProducts>
  <listOfModifiers>
    <modifierSpeciesReference species="s8"/>
    <modifierSpeciesReference species="s9"/>
  </listOfModifiers>
</reaction>

<reaction id="R01298" name="R01298" reversible="true">
  <listOfReactants>
    <speciesReference species="s20"/>
  </listOfReactants>
  <listOfProducts>
    <speciesReference species="s21"/>
  </listOfProducts>
  <listOfModifiers>
    <modifierSpeciesReference species="s8"/>
    <modifierSpeciesReference species="s9"/>
  </listOfModifiers>
</reaction>

<reaction id="R01629" name="R01629" reversible="false">
  <listOfReactants>
    <speciesReference species="s21"/>
  </listOfReactants>
  <listOfProducts>
    <speciesReference species="s109"/>
  </listOfProducts>
</reaction>

<reaction id="R01630" name="R01630" reversible="false">
  <listOfReactants>
    <speciesReference species="s21"/>
  </listOfReactants>
  <listOfProducts>
    <speciesReference species="s109"/>
  </listOfProducts>
</reaction>

The problem here is that in the last two reactions (R01629 & R01630)
there is no <listOfModifiers> node present. Responsible for the
creation of this node is the contains() call in XSLT stylesheet. While
it works for the first two reactions (R01296 & R01298) finding the
entries 8 and 9, it fails in the case of entry 41. What is wrong
here?? Maybe the Xpath query?

Thanks.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.