Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes XML and Related Technologies and the fly likes Replacing elemnt name using XSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Replacing elemnt name using XSL" Watch "Replacing elemnt name using XSL" New topic

Replacing elemnt name using XSL

Gemini Moses
Ranch Hand

Joined: Jan 04, 2001
Posts: 245
Can I do it using XSLT? How ?

Portion of Input XML file --

<table name="very_long_name" >

I want it to be converted to --

<table name="short_name" >

Please tell me how I can do this?

Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
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

Take a Minute, Donate an Hour, Change a Life
Gemini Moses
Ranch Hand

Joined: Jan 04, 2001
Posts: 245
Thanks you!!
It is sorta covered in the JavaRanch Style Guide.
subject: Replacing elemnt name using XSL
Similar Threads
Struts1: evaluating two conditions
how to do a pagination like "Page: 1 2 3 4 5 6 7" in a jsp ?
Mapping Exception
how to do hibernate mapping using natural key(s)
how to do a Pagination like "Page:1 2 3 4 5 6 " in a jsp?