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. 

33 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. wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries. keep it up.
    data analytics course in Bangalore

    ReplyDelete
  10. 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!

    Simple Linear Regression

    Correlation vs Covariance

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

    ReplyDelete
  12. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Correlation vs Covariance
    Simple linear regression
    data science interview questions

    ReplyDelete
  13. 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.

    Simple Linear Regression

    Correlation vs Covariance

    ReplyDelete
  14. 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
  15. 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
  16. I am really happy with your blog because your article is very unique and powerful for new reader.data science course in Hyderabad

    ReplyDelete
  17. 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
  18. 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
  19. 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
  20. New site is solid. A debt of gratitude is in order for the colossal exertion.
    data scientist course in hyderabad

    ReplyDelete
  21. I was basically inspecting through the web filtering for certain data and ran over your blog. I am flabbergasted by the data that you have on this blog. It shows how well you welcome this subject. Bookmarked this page, will return for extra. data science course in jaipur

    ReplyDelete
  22. 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
  23. Thanks for posting the best information and the blog is very good.business analytics course in udaipur

    ReplyDelete

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

    ReplyDelete
  25. 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
  26. 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
  27. Your explanation of using variables in XSLT for data transformation is incredibly helpful! It's a smart and efficient way to avoid unnecessary repetition of the same logic, and your clear example makes it easy for readers to understand and implement. Great job simplifying the process! 💡👏 #XSLT #DataTransformation #CodingEfficiency
    Data Analytics Courses in Mumbai

    ReplyDelete
  28. Navigating through the intricate landscape of XSLT data has never felt more like unlocking hidden pathways. This post shines a light on variables, turning the complex into a playground of understanding. It's like having a secret key to transform data sorcery into a dance of logic.
    data Analytics courses in lisbon

    ReplyDelete