Wednesday, April 23, 2014

Usage of variable in xslt (Data Transformation)

We use XSLT in data transformation and in one particular situation we might want to use same value for different fields. A variable in such case is a best approach one could think of. Below is the code snippet which is used in xslt in order to create and use a variable.

Below is a part of xslt which can be referred as an example,

<sch:ReceivedReturnCenter>
<xsl:value-of xmlns:sch="http://schemas.cordys.com/" select="concat(substring(/sch:ROConDTInput/sch:request/sch:GRDATE,7,2),substring(/sch:ROConDTInput/sch:request/sch:GRDATE,5,2),substring(/sch:ROConDTInput/sch:request/sch:GRDATE,1,4))" />
</sch:ReceivedReturnCenter>
<sch:SendBackToCustomer>
<xsl:value-of xmlns:sch="http://schemas.cordys.com/" select="concat(substring(/sch:ROConDTInput/sch:request/sch:GRDATE,7,2),substring(/sch:ROConDTInput/sch:request/sch:GRDATE,5,2),substring(/sch:ROConDTInput/sch:request/sch:GRDATE,1,4))" />
</sch:SendBackToCustomer>

Here both the target values "ReceivedReturnCenter" and "SendBackToCustomer" are mapped to a single value which is concatenation/substring of another field "GRDATE".

No doubt with this approach we would achieve the solution but its unnecessary to perform the same logic multiple times. Hence ideally we would be having the logic stored in a variable and use that variable to assign to both the target fields. Here is how we can do it,

<xsl:variable name="grDate">
<xsl:value-of xmlns:sch="http://schemas.cordys.com/" select="concat(substring(/sch:ROConDTInput/sch:request/sch:GRDATE,7,2),substring(/sch:ROConDTInput/sch:request/sch:GRDATE,5,2),substring(/sch:ROConDTInput/sch:request/sch:GRDATE,1,4))" />
</xsl:variable>
<sch:ReceivedReturnCenter>
<xsl:value-of select="$grDate" />
</sch:ReceivedReturnCenter>
<sch:SendBackToCustomer>
<xsl:value-of select="$grDate" />
</sch:SendBackToCustomer>

Usage of variable : $grDate

Note : There is a drawback of using variable in xslt as the same variable cannot be edited later (or I am not aware of :P). Variables in xslt are supposed to be initialized/assigned a value only once. 

27 comments:

  1. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
    data science

    ReplyDelete
  2. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
    Data Analytics Course in Mumbai

    ReplyDelete
  3. Such a very useful article. Very interesting to read this article. I have learn some new information.thanks for sharing. ExcelR

    ReplyDelete
  4. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
    ExcelR Business Analytics Course

    ReplyDelete
  5. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
    Data science

    ReplyDelete
  6. This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this.. best data science course in bangalore

    ReplyDelete
  7. Really impressed! Everything is very open and very clear clarification of issues. It contains truly facts. Your website is very valuable. Thanks for sharing.

    data analytics courses

    data science interview questions

    business analytics courses

    data science course in mumbai

    ReplyDelete
  8. The information provided on the site is informative. Looking forward more such blogs. Thanks for sharing .
    Artificial Inteligence course in Faridabad
    AI Course in Faridabad

    ReplyDelete
  9. Great information!! Thanks for sharing nice blog.
    Data Science Course in Hyderabad

    ReplyDelete
  10. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.data science course in Hyderabad

    ReplyDelete
  11. Numerous website admins are continually hoping to spare time by recruiting others to do physical work so they can concentrate more on promoting and refreshing their sites. database data entry services

    ReplyDelete
  12. I am really happy with your blog because your article is very unique and powerful for new reader.data science course in Hyderabad

    ReplyDelete
  13. Very nice blogs!!! i have to learning for lot of information for this sites…Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing, data science online course

    ReplyDelete
  14. Your work is very good, and I appreciate you and hopping for some more informative posts
    <a href="https://www.excelr.com/business-analytics-training-in-pune/”> Courses in Business Analytics</a> have express a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon…
    I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job !

    ReplyDelete
  15. A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one.
    data scientist course in hyderabad

    ReplyDelete
  16. New site is solid. A debt of gratitude is in order for the colossal exertion.
    data scientist course in hyderabad

    ReplyDelete
  17. The information in the post you posted here is useful because it contains some of the best information available. Thanks for sharing it. Keep up the good work Graphic Designing Services.

    ReplyDelete

  18. This blog consistently delivers high-quality content on data science topics. Kudos to the author!
    Data Science training In Faridabad

    ReplyDelete
  19. A clever method for data transformation in XSLT is the use of variables. By utilizing the same logic again and again, like in your case, it optimizes code. Just keep in mind that once set, XSLT variables cannot be changed. Great advice!👍
    Data Analytics Courses in India

    ReplyDelete
  20. Thanks for the informative post on using variables in XSLT. It's a great way to avoid repeating the same logic multiple times, and it's good to know about the limitation of not being able to edit variables later.
    Data Analytics Courses in Nashik

    ReplyDelete
  21. I appreciate your enlightening post on using variables in XSLT. It's a terrific approach to prevent having to use the same reasoning several times, but it's important to be aware of the drawback of being unable to change variables later.
    Data Analytics Courses in Agra

    ReplyDelete
  22. Your blog post on the usage of variables in XSLT for data transformation is a comprehensive guide for anyone looking to harness the full power of XSLT in their data transformation processes.
    Digital marketing courses in illinois

    ReplyDelete
  23. The blog on the usage of variables in XSLT for data transformation provides a clear and insightful guide. It effectively highlights how variables in XSLT contribute to a more efficient and modular approach to transforming XML data.
    Data analytics framework

    ReplyDelete