Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replacing elemnt name using XSL

 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I do it using XSLT? How ?

Portion of Input XML file --

<table name="very_long_name" >
....
....
</table>

I want it to be converted to --

<table name="short_name" >
.....
......
</table>


Please tell me how I can do this?

Thanks!
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure it can be done.
Something like -

<xsl:variable name="newTableName" select="substring(/Table/@name, 10)"/>

This truncates the value of Table/@name attribute and returns the forst 10 chars, which you can use as the 'short-name' for the new table element that you write after transforming.

The constructs you are looking for are substring, substring-before and substring-after. Check the XSLT/XPath specs for the details on these functions. Don't have the links handy right now.

- m
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic