[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

XSLT Transformation Problem !

Posted on 2006-06-05
9
Medium Priority
?
483 Views
Last Modified: 2013-11-18
Hi
I am new to XSLT and i am having problems doing a translation. Can anyone help ?

This is a snapshot of my XML file that i which to transform.

-------------------------------------------------------------------------------------------------------------------------------------
<data name="list">
   <grid>
      <row>
         <data name="item" entity="entity-item" attribute="attribute-item" value="q100">
            <question id="q100" name="q100 name" position="1">
               <data>
                  <datum unit="MT1" reference="101" name="Amount" attribute="amount" value="£ 100.00"/>
                  <datum unit="MT1" reference="101" name="Age" attribute="ind" value="Yes"/>
               </data>
            </question>
            <oldData unit="TT1"/>
         </data>
         <data name="item" entity="entity-item" attribute="attribute-item" value="q100">
            <question id="q100" name="q100 name" position="2">
               <data>
                  <datum unit="MT1" reference="101" name="Amount" attribute="amount" value="£ 200.00"/>
                  <datum unit="MT1" reference="101" name="Age" attribute="ind" value="No"/>
               </data>
            </question>
            <oldData unit="TT1"/>
         </data>
         <data name="item" entity="entity-item" attribute="attribute-item" value="q100">
            <question id="q100" name="q100 name" position="3">
               <data>
                  <datum unit="MT1" reference="101" name="Amount" attribute="amount" value="£ 300.00"/>
                  <datum unit="MT1" reference="101" name="Age" attribute="ind" value="Yes"/>
               </data>
            </question>
            <oldData unit="TT1"/>
         </data>
         <data name="item" entity="entity-item" attribute="attribute-item" value="q100">
            <question id="q100" name="q100 name" position="4">
               <data>
                  <datum unit="MT1" reference="101" name="Amount" attribute="amount" value="£ 400.00"/>
                  <datum unit="MT1" reference="101" name="Age" attribute="ind" value="Yes"/>
               </data>
            </question>
            <oldData unit="TT1"/>
         </data>
        .....
        .....
        .....
      </row>
   </grid>
</data>


Now what i want to do is for every datum node with the a ' value="Yes" ', i want to
1) Update the <oldData unit="TT1"/>, so that the 'unit' = "TT2"
2) Update the <datum unit="MT1" reference="101" name="Amount" attribute="amount" value="£ 400.00"/>, so that the value of 'unit' it "MT2"
3) Finally i need to remove all <datum unit="MT1" reference="101" name="Age" attribute="ind" value="Yes"/>  regardless of value = yes or no.


I can do step one with the following XSLT, but am struggling with steps 2 and 3, can anyone help ?

-----------------------------------------------------------------------------
<!-- Update oldData attribute to TT2 -->
<xsl:template match="oldData[ancestor::data/question[@id='q100']//datum[@attribute='ind'][@value='Yes']]">
  <xsl:copy>
          <xsl:copy-of select="@*[name() != 'unit']"/>
          <xsl:attribute name="unit">TT2</xsl:attribute>
  </xsl:copy>              
</xsl:template>


Many thanks for any help ? Maybe i need to start again and rethink but my transformations, i think i am perhaps doing things in the wrong order....

Thanks

m
0
Comment
Question by:Molko
  • 3
  • 3
  • 2
8 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16834608
Hi Molko,

2) must be very similar to 1)
    <xsl:template match="datum[@name='Amount'][parent::data[datum[@attribute='ind'][@value='Yes']]]">
        <xsl:copy>
            <xsl:copy-of select="@*[name() != 'unit']"/>
            <xsl:attribute name="unit">MT2</xsl:attribute>
        </xsl:copy>              
    </xsl:template>


Cheers!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 16834624
Molko,

and here is 3)

    <xsl:template match="datum[@name='Age']"/>
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 16834629
Molko,

the full copying stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="node() | text()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node( )| text()" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="oldData[ancestor::data/question[@id='q100']//datum[@attribute='ind'][@value='Yes']]">
        <xsl:copy>
            <xsl:copy-of select="@*[name() != 'unit']"/>
            <xsl:attribute name="unit">TT2</xsl:attribute>
        </xsl:copy>              
    </xsl:template>
    <xsl:template match="datum[@name='Amount'][parent::data[datum[@attribute='ind'][@value='Yes']]]">
        <xsl:copy>
            <xsl:copy-of select="@*[name() != 'unit']"/>
            <xsl:attribute name="unit">MT2</xsl:attribute>
        </xsl:copy>              
    </xsl:template>
    <xsl:template match="datum[@name='Age']"/>
   
</xsl:stylesheet>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:avernet
ID: 16835102
Molko,

Gertone stylesheet seems to work just great. BTW, to test it out quickly on your XML, you can use the page below, paste the XML you want to transform in the first text area, paste the XSLT in the second one, and the result appears at the bottom. There is no "submit" button and the result of the transformation is updated as you type.

http://www.orbeon.com/ops/goto-example/xslt

Alex
--
Blog (XML, Web apps, Open Source):
http://www.orbeon.com/blog/

0
 

Author Comment

by:Molko
ID: 16835733
Nice one, i have learnt a lot from that...
0
 
LVL 1

Expert Comment

by:avernet
ID: 16835878
Molko,

I am flattered that you marked my comment at the accepted answer, but shouldn't Gertone's comments be marked as accepted answer instead? He is the one who really wrote the stylesheet that solves your problem :).

Alex
--
Blog (XML, Web apps, Open Source):
http://www.orbeon.com/blog/

0
 

Author Comment

by:Molko
ID: 16836056
avernet

Oooops, sorry that was a slip of the mouse, how can i undo my error ?
0
 
LVL 1

Expert Comment

by:avernet
ID: 16836111
Molko,

Try posting a message in the Community Support, asking an admin to do this change for you. Questions in Community Support don't use your points.

http://www.experts-exchange.com/Community_Support/

Alex
--
Blog (XML, Web apps, Open Source):
http://www.orbeon.com/blog/

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question