469,275 Members | 1,287 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

A conversion using XSLT.

I have an Source XML called SubOrderMessage.xml which needs to be transformed

Expand|Select|Wrap|Line Numbers
  1.  
  2. Source 'SubOrderMessage.xml'
  3. ---------------------------
  4. <?xml version="1.0" encoding="UTF-8"?>
  5. <FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4">
  6. <Order Acct="1" ExDest="ExchDest" ><Hdr Snt="2007-04-05T13:34:47" /><Instrmt Issr="Barclays" MMY="200903" /></Order></FIXML>
  7.  
  8.  
to be converted into:

Expand|Select|Wrap|Line Numbers
  1.  
  2. OUTPUT XML
  3. ----------
  4.  
  5. <?xml version="1.0" encoding="UTF-8" ?> 
  6. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" 
  7. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.fixprotocol.org/FIXML-4-4" 
  8. xmlns:i="http://www.ABC.com/interests:i">
  9. <xsl:output method="xml"/>
  10.  
  11. <i:ID>1</i:ID>
  12. <i:Date>2007-04-05</i:Date>
  13. <i:Issuer>Barclays</i:Issuer>
  14.  
  15.  
Even though the above elements are in namespace 'i:',I am trying the below,but am unable to get the output

My xsl is:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="UTF-8" ?> 
  3. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" 
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.fixprotocol.org/FIXML-4-4" 
  5. xmlns:i="http://www.ABC.com/interests:i">
  6. <xsl:output method="xml"/>
  7. <xsl:template match="/">
  8.  
  9. <i:ID><xsl:value-of select="Order@Acct" /> </i:ID>
  10.  
  11.  
  12.  
Can someone please help me out to get the above output please?
No offence meant.
Apr 16 '07 #1
3 1712
dorinbogdan
839 Expert 512MB
Something is wrong in the XML with xmlns="http://www.fixprotocol.org/FIXML-4-4"
Remove the xmlns attribute from <FIXML> element and then
<xsl:value-of select="FIXML/Order/@Acct" /> works.
Apr 16 '07 #2
Yes,thats what I had guessed and removed it off.

How do I get the value of Hdr which is an element under Oder?
Have I done the right way as below?


Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="UTF-8" ?> 
  3. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
  4. <xsl:output method="xml"/>
  5.  
  6. <xsl:template match="FIXML">
  7. <xsl:apply-templates  select ="Order"/>
  8. <xsl:apply-templates  select ="Order/Hdr"/>
  9. </xsl:template>
  10.  
  11. <xsl:template match="Order">
  12. <ID>
  13. <xsl:value-of select="@Acct"/> 
  14. </ID>
  15. </xsl:template>
  16.  
  17. <xsl:template match="Order/Hdr">
  18. <SD>
  19. <xsl:value-of select="@Snt"/> 
  20. </SD>
  21. </xsl:template>
  22.  
  23. </xsl:stylesheet>
  24.  
Apr 16 '07 #3
dorinbogdan
839 Expert 512MB
If want to see the <ID and <SD> tags in browser, then update the code like this:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="FIXML">
  2.     <xsl:apply-templates  select ="Order"/>
  3. </xsl:template>
  4.  
  5. <xsl:template match="Order">
  6.     &lt;ID&gt;    
  7.         <xsl:value-of select="@Acct"/> 
  8.     &lt;/ID&gt;
  9.  
  10.     &lt;SD&gt;     
  11.         <xsl:value-of select="Hdr/@Snt"/> 
  12.     &lt;/SD&gt;
  13. </xsl:template>
  14.  
Apr 16 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by plopez | last post: by
12 posts views Thread by hawat.thufir | last post: by
1 post views Thread by PAjay | last post: by
2 posts views Thread by sethridge1991 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.