Molko
asked on
XSLT Transformation Problem !
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::d ata/questi on[@id='q1 00']//datu m[@attribu te='ind'][ @value='Ye s']]">
<xsl:copy>
<xsl:copy-of select="@*[name() != 'unit']"/>
<xsl:attribute name="unit">TT2</xsl:attri bute>
</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
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"
<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"
<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"
<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"
<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::d
<xsl:copy>
<xsl:copy-of select="@*[name() != 'unit']"/>
<xsl:attribute name="unit">TT2</xsl:attri
</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
Molko,
and here is 3)
<xsl:template match="datum[@name='Age']" />
and here is 3)
<xsl:template match="datum[@name='Age']"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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/
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/
ASKER
Nice one, i have learnt a lot from that...
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/
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/
ASKER
avernet
Oooops, sorry that was a slip of the mouse, how can i undo my error ?
Oooops, sorry that was a slip of the mouse, how can i undo my error ?
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.
https://www.experts-exchange.com/Community_Support/
Alex
--
Blog (XML, Web apps, Open Source):
http://www.orbeon.com/blog/
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.
https://www.experts-exchange.com/Community_Support/
Alex
--
Blog (XML, Web apps, Open Source):
http://www.orbeon.com/blog/
2) must be very similar to 1)
<xsl:template match="datum[@name='Amount
<xsl:copy>
<xsl:copy-of select="@*[name() != 'unit']"/>
<xsl:attribute name="unit">MT2</xsl:attri
</xsl:copy>
</xsl:template>
Cheers!