1

This is my first post on here and I am hoping someone will be able to help me as I have been racking my brain for ages trying to access a particular element in my XML using my existing XSL. I have searched the site and have come close to finding the answer but it was never exactly what I was looking for.

The new element I am trying to process is , ideally I am looking to be able to reference the 'Label' within NOTE to extract the corresponding value. For example, in the below XML I would like to be able to extract the value of the "Unit" label which is KT and store that in <UOM>.

The XML is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<TYRE xmlns="gapi-tyre-com" Action="Update">
   <INSTSPECIFIER SEQ="10000"/>
   <TERM Default="" Desc="" Label="Execution" Type="string">MTT</TERM>
   <ANNOTATIONS>
      <NOTE Label="CP">2013-12-03T15:38:48.931</NOTE>
      <NOTE Label="CPR">UK</NOTE>
      <NOTE Label="Unit">KT</NOTE>
      <NOTE Label="UnitID">10000554</NOTE>
   </ANNOTATIONS>
</TYRE>

The current XSL I have is:

<?xml version="1.0" encoding="UTF-8"?>

<!-- Version 1.0.001 -->

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:g="gapi-tyre-com"
exclude-result-prefixes="g">

<xsl:output method="xml" indent="yes" doctype-public="importFile" doctype-system="importer.dtd"/>

<xsl:template match="/">
    <xsl:element name="importFile">
        <xsl:attribute name="source">T</xsl:attribute>
        <xsl:attribute name="template">default</xsl:attribute>
        <xsl:apply-templates select="g:TYRE"/>
    </xsl:element>
</xsl:template>       

<xsl:template match="g:TYRE">
  <TYREImport>
    <xsl:choose> 
        <xsl:when test="@Action = 'Remove'">
            <audit>DELETE</audit>
        </xsl:when>         
        <xsl:otherwise>
            <audit>NEW</audit>
        </xsl:otherwise>        
    </xsl:choose>
            <type>F</type>
    <period>H</period>
    <ABCD>D</ABCD>
    <TYREtype2>P</TYREtype2>
    <mt>F</mt>      
    <memo1> MTT , <xsl:value-of select="g:INSTSPECIFIER/@SEQ"/></memo1>             
  </TYREImport>

</xsl:template>
</xsl:stylesheet>

Any help would be much appreciated on this.

1 Answer 1

2

If I understand you correctly, you want to show the value of <NOTE Label="Unit">?

  <TYREImport>
     ....
     <UOM>
        <xsl:value-of select="g:ANNOTATIONS/g:NOTE[@Label='Unit']" />
     </UOM>
  </TYREImport>
Sign up to request clarification or add additional context in comments.

1 Comment

Thats the one I was looking for... I think I was going down the wrong route using xsl:for-each. Thank you very much for your quick response and I'm sorry if that was a bit too easy. Happy New Year!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.