Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing using XSLT

 
Abhishek Rath
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have to write a XSLT which can remove the last occurrence of the string. The string can have value like

Handmade Paper Wall Art - Floating Square + Dots 23"

Handmade Paper Wall Art" - Floating Square + Dots 23"

Handmade Paper Wall Art - Floating Square + Dots 23" (12"X11")

In the above case only the 1st string , the last " will be removed and other cases it will not remove anything.Please note we are using XSLT 1.0 . Please need your help to get the correct method in XSLT.


Regards
Abhishek
 
Paul Clapham
Sheriff
Pie
Posts: 20756
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume that these strings are embedded in an XML document. And I assume that the result you want is a copy of that XML document, only with the changes you described applied.

Is that correct?

If so then first of all you need the XSLT identity transformation, and then you need to include a template which selects the nodes you need changed. That template should use the substring() function and possibly the string-length() function and output the result of the code.
 
Abhishek Rath
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Yes these are present in a XML document and using XSLT 1.0 I am creating a feed file. I am not able to determine the last occurrence of " in the String name.

For example we have the strings as below

abc cdv" and a"cd fr"dd.

Now my code is removing the " from both the string. The output is abc cdv and a"cd frdd . However it should only remove the " from the 1st string and the 2nd string should be untouched. I am using the below code



Please help.

Regards
Abhishek
 
Paul Clapham
Sheriff
Pie
Posts: 20756
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to explain your requirements first. Apparently you sometimes want to remove quote characters from the string, but not always. But it's hard to guess when that "sometimes" is.
 
Abhishek Rath
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

The requirement is to remove the " ONLY IF this is the last character of a string.

Regards
Abhishek
 
Paul Clapham
Sheriff
Pie
Posts: 20756
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. That would be where the "string-length" function comes into the picture, then. Your code so far uses the "contains" function, which doesn't look only at the end.
 
Abhishek Rath
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks...However I am not getting exactly where to use the String-lenght function in my code.Could you please help me on this?
 
g tsuji
Ranch Hand
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like this.

No need of recursion in this case if I understand correctly your requirement.
 
Abhishek Rath
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.I will try and let you know.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic