jQuery in Action, 3rd edition
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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!!
I agree. Here's the link: http://aspose.com/file-tools
subject: Replacing elemnt name using XSL
It's not a secret anymore!