aspose file tools*
The moose likes XML and Related Technologies and the fly likes Parsing using XSLT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsing using XSLT" Watch "Parsing using XSLT" New topic
Author

Parsing using XSLT

Abhishek Rath
Ranch Hand

Joined: Nov 22, 2007
Posts: 38
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
Bartender

Joined: Oct 14, 2005
Posts: 18903
    
    8

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

Joined: Nov 22, 2007
Posts: 38
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
Bartender

Joined: Oct 14, 2005
Posts: 18903
    
    8

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

Joined: Nov 22, 2007
Posts: 38
Hi

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

Regards
Abhishek
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18903
    
    8

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

Joined: Nov 22, 2007
Posts: 38
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

Joined: Jan 18, 2011
Posts: 543
    
    3
Like this.

No need of recursion in this case if I understand correctly your requirement.
Abhishek Rath
Ranch Hand

Joined: Nov 22, 2007
Posts: 38
Thanks a lot.I will try and let you know.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Parsing using XSLT