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 July 27th, 2010, 06:36 PM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Question Nested attribute in XML file (***)

So sorry...Mr.mhkay.......I've edited my source document. Could you help me fix the transformation document?
I have the XML source file that presents like this:
Code:
<process id='a001' name='proc111'>

  <laneset>
   <lane id='c001' name='User111'>
     <referenceElements>d001</referenceElements>
   </lane>
   <lane id='c002' name='User222'/>
     <referenceElements>d002</referenceElements>
    </lane>
  </laneset>

  <startevent id='d001' name='startevent111'/>
  <gateway id='d002' name='gateway111'/>

</process>

  <process id='a002' name='proc222'>
  <laneset>
    <lane id='c001' name='customer'>
       <referenceElements>d003</referenceElements>
    </lane>
  </laneset>
  <endevent id='d003' name='endevent111'/>

</process>
-----------------------------------------------

i wanna tranform to XML target as following document:
Code:
<svg>
<g id='a001' class='pools'>
    <g id='b001' class='pool' name='Proc111'>
        <g id='c001' class='lane' name='User111' PoolID='b001'>
           <g id='d001' class='startevent' name='startevent111' LaneID='c001'></g>
        </g>  
        <g id='c002' class='lane' name='User222' PoolID='b001'>
            <g id='d002' class='gateway' name='gateway111' LaneID='c002'></g>
        </g>
    </g>

     <g id='b002' class='pool' name='Proc222'>
       <g id='c003' class='lane' name=' customer ' PoolID=' b002'>
          <g id='d003' class='endevent' name='endevent111' LaneID='c003'>  </g>
      </g>
    </g>
</g>
</svg>
------------------
My transformation file:
---------
Code:
<xsl:template match="/">
	<svg>
	<xsl:apply-templates/>						
	</svg>		
</xsl:template>
<xsl:template match="process">
  <g id="{@id}" name="{@name}" class="POOL">
     <xsl:apply-templates select="laneset/lane"/>
  </g>
</xsl:template>

<xsl:template match="lane">
  <g id="{@id}" class="LANE" name="{@name}" PoolID="parent::current()/@id">
     <xsl:variable name="p" select="count(preceding-sibling::lane)+1"/>
     <xsl:variable name="ref" select="ancestor::process/*[$p+1]"/>
     <xsl:apply-templates select="$ref"/>
  </g>
</xsl:template>

<xsl:template match="startevent">
  <g id="{@id}" class="startevent" name="{@name}"   LaneID="{parent::current()/@id}"/>
</xsl:template>
<xsl:template match="endevent">
  <g id="{@id}" class="endevent" name="{@name}"   LaneID="{parent::current()/@id}"/>
</xsl:template>
<xsl:template match="gateway">
  <g id="{@id}" class="gateway" name="{@name}"   LaneID="{parent::current()/@id}"/>
</xsl:template>
</xsl:stylesheet>
Could you see my problems?

Last edited by metinhoclam; August 1st, 2010 at 06:09 PM.. Reason: change the new source code
 
Old July 27th, 2010, 07:12 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It doesn't look difficult, but I'm not sure I fully understand the requirement. Where does the LaneID c001 come from? Why is startevent111 associated with user111 and gateway111 with user222 - is it simply a positional relationship?

You'll want a set of template rules something like this:

Code:
<xsl:template match="process">
  <g id="{@id}" name="{@name}" class="pool">
     <xsl:apply-templates select="laneset/lane"/>
  </g>
</xsl:template>

<xsl:template match="lane">
  <g id="{???}" class="lane" name="{@name}" PoolID="{???}">
     <xsl:variable name="p" select="count(preceding-sibling::lane)+1"/>
     <xsl:variable name="ref" select="ancestor::process/*[$p+1]"/>
     <xsl:apply-templates select="$ref"/>
  </g>
</xsl:template>

<xsl:template match="startevent">
  <g id="{@id}" class="startevent" name="{@name}" LaneID="{???}"/>
</xsl:template>
The ??? are places where I can't work out how you get the output value.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
metinhoclam (July 28th, 2010)
 
Old July 28th, 2010, 01:01 PM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default

The process has the same name with the pool. Inside the pool is a lot of lanes. For each lane, there are some activities/notations such as: startevent, endevent, gateway, and the other notation of BPMN. So, each lane have to indicate its PoolID that is referenced from the id of Pool where lane is located.
Similarly, each activities/notations inside the lane have to reveal LaneID that is referenced from the id of Lane where activities/notation is located.

The main thing is how each element references to its parent..

Last edited by metinhoclam; August 2nd, 2010 at 03:44 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Split xml file with result document and javax.xml.transform.Transformer. nisargmca XSLT 3 January 12th, 2010 06:26 AM
Using XSLT to tranform XML into JSF pdimilla XSLT 4 July 3rd, 2009 03:50 AM
VB.net, adding XML data to an existing XML file saikoboarder XML 11 April 17th, 2008 04:19 PM
get error while tranform blank xml pradipkumar XSLT 4 November 20th, 2007 01:42 AM
DTS Package, XML task. Read XML file and store it Victoria SQL Server DTS 0 July 24th, 2006 02:43 PM





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