• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parsing using XSLT

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot.I will try and let you know.
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic