"Regular expression"-style replace in XSLT 1.0 -


I need to use XSLT 1.0 and change which is really suited for regular expressions. Unfortunately these are not available in 1.0 and I'm unable to use any extension libraries such as EXSLT due to security settings. I can not change.

The string I am working with looks like this:

19; # John Smith; # 17; # Ban reynolds; # 1; # Terry jackson

I need to change the number and ; # with the letter , . For example, the above will change:

John Smith, Ben Reynolds, Terry Jackson

I know that recursive string function is required, maybe substrings Use and translate, but I'm not sure where to start with it.

Do anyone have some hints to work on this? Here I started with:

  & lt; Xsl: template name = "trimmulti" & gt; & Lt; Xsl: Ultimate Name = "FullString" /> & Lt; Xsl: variable name = "normalized string" & gt; & Lt; Xsl: Select the value = "general-location ($ fullstring)" /> & Lt; / XSL: variable & gt; & Lt; Xsl: variable name = "hash" & gt; # & Lt; / Xsl: variable & gt; & Lt; XSL: Select & gt; & Lt; Xsl: when test = "($ normalized string, $ hash) is included" & gt; & Lt ;! - Do something and call Tri - Multi - & gt; & Lt; / XSL: When & gt; & Lt; / XSL: Select & gt; & Lt; / XSL: Templates & gt;  

I hope you did not make the problem very easy to ask for it , Because it should not be a problem.

You can define a template and you can call it again until you keep the format of the input string stable.

For example,

  & lt; Xsl: Template Name = "Trim Multi" & gt; & Lt; Xsl: Ultimate Name = "Input String" / & gt; & Lt; Xsl: variable name = "relay string" = "substring-after ($ InputString, '; #')" /> & Lt; XSL: Select & gt; & Lt; Xsl: when test = "contains ($ string, '; #')" & gt; & Lt; Xsl: select value = "substring-before ($ residue string, '; #')" /> & Lt; Xsl: text & gt ;, & lt; / Xsl: text & gt; & Lt; Xsl: call-template name = "trim multi" & gt; & Lt; With xsl: select param name = "inputstring" = "substring-after ($ residue string, '; #')" /> & Lt; / XSL: Call-templates & gt; & Lt; / XSL: When & gt; & Lt; XSL: otherwise & gt; & Lt; Xsl: Select Value = "$ Remnant String" / & gt; & Lt; / XSL: otherwise & gt; & Lt; / XSL: Select & gt; & Lt; / XSL: Templates & gt;  

I tested this callout with the following call:

  & lt; Xsl: template match = "/" & gt; & Lt; Xsl: call-template name = "trim multi" & gt; & Lt; Xsl: with-param name = "inputstring" & gt; 19; # John Smith; # 17; # Ben Reynolds; # 1; # Tiny jackson & lt; / Xsl: with-param & gt; & Lt; / XSL: Call-templates & gt; & Lt; / XSL: Templates & gt;  

and found the following output:

  John Smith, Ben Reynolds, Terry Jackson  

Which looks like You are after.

It is easy to explain what this is doing if you are familiar with functional programming; InputString parameter always [number]; # [Name]; # [Rest string] occurs in. [number] for each call of trim multi ; Close the part and print [name] part, then the remaining expression

the base case occurs when InputString form [Number]; # [Name] , in that case the relaying string is in the ; # will not be Since we know that this is the end of input, we do not produce a comma at this time.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -