Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 23rd, 2007, 04:13 AM
Registered User
 
Join Date: Aug 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Comparing nodes attribute(Michael Kay help meeee)

I am stuck at implementing the following logic:
>
> I have the following two nodes at the same level :
>
> The first node is about a package:
>
> <ownedMember xmi:type="uml:Package" xmi:id="_M-CnxU4wEdy-a6vbxd4tOQ"
> name="UML Standard Profile">
> .......
> ..../* contains some extra nodes in here */
> </ownedMember>
>
> now there is a possibility that there is a refinement...(jus discard the
> technical term) which is indicated by the presence of below node
>
> <ownedMember xmi:type="uml:Stereotype" xmi:id="_M-Cnv04wEdy-a6vbxd4tOQ"
> name="feature module">
> ......../* contains some extra nodes in here not same as thwe prev node*/
> ......
> </ownedMember>
>
> In my XSLT I need to check if there is a matching refinement for a
> package. The mapping is done by the xmi:id which carries the same value in
> both the nodes
>
> In words I want to do the following check:
> XMI:ID of /ownedMember[@xmi:type="uml:Package] = XMI ID
> of/ownedMember[@xmi:type="uml:Stereotype" and @name="feature module"]
>
> Please help me.....
>
> Thanks in advance.


 
Old August 23rd, 2007, 04:34 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Apologies for not being Michael Kay :)
If the ownedMember where the xmi:type="uml:Package" is the context node you need:
Code:
following-sibling::ownedMember[@xmi:type="uml:Stereotype" and @name="feature module" and @xmi:id = current()/@xmi:id]
If the second node isn't guaranteed to follow the first and be at the same level then you may need to choose a different axis from following-sibling.

--

Joe (Microsoft MVP - XML)
 
Old August 23rd, 2007, 04:48 AM
Registered User
 
Join Date: Aug 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe Thanks a lot for the quickly reply man!!!

Your help is very much appreciated!!!



 
Old August 23rd, 2007, 07:19 AM
Registered User
 
Join Date: Aug 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe,
could you help me with this please..This is the XSLT I have written:

<xsl:template match="ownedMember[@xmi:type='uml:Package'] ">
            <xsl:if test="/uml:Model/ownedMember[@xmi:type='uml:Stereotype' and @name='feature module' and @xmi:id = current()/@xmi:id]">
                <xsl:element name='xak:extends'>
                    <xsl:attribute name="xak:module"><xsl:value-of select='concat("m", translate(@name, " ", "_") )' /></xsl:attribute>
                    <xsl:element name='xak:super'>
                        <xsl:attribute name="xak:module"><xsl:value-of select='concat("m", translate(@name, " ", "_") )' /></xsl:attribute>
                        <xsl:apply-templates select = "./ownedMember[@xmi:type= 'uml:Class']"/>
                    </xsl:element>
                </xsl:element>
            </xsl:if>
            <xsl:apply-templates/>
        </xsl:template>

        <xsl:template match="ownedMember[@xmi:type= 'uml:Class']">
            <xsl:choose>
                <xsl:when test="/uml:Model/ownedMember[@xmi:type='uml:Stereotype' and @name='class refinement' and @xmi:id = current()/@xmi:id]">
                    <xak:extends>
                        <xsl:attribute name="xak:module"><xsl:value-of select='concat("m", translate(@name, " ", "_") )' /></xsl:attribute>
                        <xak:super>
                            <xsl:attribute name="xak:module"><xsl:value-of select='concat("m", translate(@name, " ", "_") )' /></xsl:attribute>
                            <xsl:copy-of select="./*"/>
                        </xak:super>
                    </xak:extends>
                </xsl:when>
                <xsl:otherwise>

                    <xsl:copy-of select="./*"/>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:apply-templates/>
        </xsl:template>

But both the if:test are failing are failing

The source file is:
<uml:Model>
  <ownedMember xmi:type="uml:Stereotype" xmi:id="_M-Cnv04wEdy-a6vbxd4tOQ" name="feature module">
    <ownedAttribute xmi:id="_M-CnwE4wEdy-a6vbxd4tOQ" name="base_Package" visibility="private" association="_M-CnwU4wEdy-a6vbxd4tOQ">
      <type xmi:type="uml:Class" href="pathmap://UML2_METAMODELS/UML2.metamodel.uml2#_m82oYa86EdiEh75YJ_3n8g"/>
    </ownedAttribute>
  </ownedMember>

  <ownedMember xmi:type="uml:Extension" xmi:id="_M-CnwU4wEdy-a6vbxd4tOQ" memberEnd="_M-Cnwk4wEdy-a6vbxd4tOQ _M-CnwE4wEdy-a6vbxd4tOQ">
    <ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_M-Cnwk4wEdy-a6vbxd4tOQ" name="extension_" visibility="private" type="_M-Cnv04wEdy-a6vbxd4tOQ" association="_M-CnwU4wEdy-a6vbxd4tOQ" aggregation="composite">
      <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_M-Cnw04wEdy-a6vbxd4tOQ" value="1"/>
      <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_M-CnxE4wEdy-a6vbxd4tOQ"/>
    </ownedEnd>
  </ownedMember>
  <ownedMember xmi:type="uml:Package" xmi:id="_M-CnxU4wEdy-a6vbxd4tOQ" name="UML Standard Profile">
    <ownedComment xmi:id="_M-Cnxk4wEdy-a6vbxd4tOQ" body="UML Standard Profile contains several popular stereotypes, tag definitions and constraints described in UML 1.4 and UML 2.0 Specifications." annotatedElement="_M-CnxU4wEdy-a6vbxd4tOQ"/>
  </ownedMember>
  <ownedMember xmi:type="uml:Package" xmi:id="_M-Cnx04wEdy-a6vbxd4tOQ" name="MinutePlus">
    <ownedMember xmi:type="uml:Class" xmi:id="_M-CnyE4wEdy-a6vbxd4tOQ" name="KeyPad">
      <ownedAttribute xmi:id="_M-CnyU4wEdy-a6vbxd4tOQ" name="minPlusButton" visibility="private"/>
      <ownedOperation xmi:id="_M-Cnyk4wEdy-a6vbxd4tOQ" name="initElements">
        <returnResult xmi:id="_M-Cny04wEdy-a6vbxd4tOQ" direction="return">
          <type xmi:type="uml:PrimitiveType" href="UML_Standard_Profile.MagicDraw_Profile.profi le.uml2#_M-G5LU4wEdy-a6vbxd4tOQ"/>
        </returnResult>
        <type xmi:type="uml:PrimitiveType" href="UML_Standard_Profile.MagicDraw_Profile.profi le.uml2#_M-G5LU4wEdy-a6vbxd4tOQ"/>
      </ownedOperation>
      <ownedOperation xmi:id="_M-CnzE4wEdy-a6vbxd4tOQ" name="setupPanels">
        <returnResult xmi:id="_M-CnzU4wEdy-a6vbxd4tOQ" direction="return">
          <type xmi:type="uml:PrimitiveType" href="UML_Standard_Profile.MagicDraw_Profile.profi le.uml2#_M-G5LU4wEdy-a6vbxd4tOQ"/>
        </returnResult>
        <type xmi:type="uml:PrimitiveType" href="UML_Standard_Profile.MagicDraw_Profile.profi le.uml2#_M-G5LU4wEdy-a6vbxd4tOQ"/>
      </ownedOperation>
      <ownedOperation xmi:id="_M-Cnzk4wEdy-a6vbxd4tOQ" name="initListeners">
        <returnResult xmi:id="_M-Cnz04wEdy-a6vbxd4tOQ" direction="return">
          <type xmi:type="uml:PrimitiveType" href="UML_Standard_Profile.MagicDraw_Profile.profi le.uml2#_M-G5LU4wEdy-a6vbxd4tOQ"/>
        </returnResult>
        <type xmi:type="uml:PrimitiveType" href="UML_Standard_Profile.MagicDraw_Profile.profi le.uml2#_M-G5LU4wEdy-a6vbxd4tOQ"/>
      </ownedOperation>
      <ownedOperation xmi:id="_M-Cn0E4wEdy-a6vbxd4tOQ" name="minPlusListener">
        <returnResult xmi:id="_M-Cn0U4wEdy-a6vbxd4tOQ" direction="return">
          <type xmi:type="uml:PrimitiveType" href="UML_Standard_Profile.MagicDraw_Profile.profi le.uml2#_M-G5LU4wEdy-a6vbxd4tOQ"/>
        </returnResult>
        <type xmi:type="uml:PrimitiveType" href="UML_Standard_Profile.MagicDraw_Profile.profi le.uml2#_M-G5LU4wEdy-a6vbxd4tOQ"/>
      </ownedOperation>
    </ownedMember>
  </ownedMember>

  <ownedMember xmi:type="uml:Stereotype" xmi:id="_M-Cn0k4wEdy-a6vbxd4tOQ" name="class refinement">
    <ownedAttribute xmi:id="_M-Cn004wEdy-a6vbxd4tOQ" name="base_Class" visibility="private" association="_M-Cn1E4wEdy-a6vbxd4tOQ">
      <type xmi:type="uml:Class" href="pathmap://UML2_METAMODELS/UML2.metamodel.uml2#_m88uxq86EdiEh75YJ_3n8g"/>
    </ownedAttribute>
  </ownedMember>

  <ownedMember xmi:type="uml:Extension" xmi:id="_M-Cn1E4wEdy-a6vbxd4tOQ" memberEnd="_M-Cn1U4wEdy-a6vbxd4tOQ _M-Cn004wEdy-a6vbxd4tOQ">
    <ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_M-Cn1U4wEdy-a6vbxd4tOQ" name="extension_" visibility="private" type="_M-Cn0k4wEdy-a6vbxd4tOQ" association="_M-Cn1E4wEdy-a6vbxd4tOQ" aggregation="composite">
      <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_M-Cn1k4wEdy-a6vbxd4tOQ" value="1"/>
      <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_M-Cn104wEdy-a6vbxd4tOQ"/>
    </ownedEnd>
  </ownedMember>

</uml:Model>

Appreciate your time and help.

Regards,
Sathish

 
Old August 25th, 2007, 03:21 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Is that the full XML source, there are no namespace declarations? Your matching path starts with / so uml:Model must be the document element for this test to succeed.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting some nodes by attribute value acw274 XSLT 8 July 2nd, 2008 01:22 AM
How can I go through all child nodes & attribute.. vishnu108mishra C# 1 November 13th, 2007 05:00 AM
XPath - Selecting nodes based on attribute values billy_bob_the_3rd XML 4 December 1st, 2004 06:12 PM
How to get attribute values after comparing attrib DipeshKhakhkhar XSLT 0 August 26th, 2003 01:14 PM
passing attribute info while traversing nodes Ashley XML 1 June 20th, 2003 07:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.