xslt - Using grouping to pull together text and then test it -
In this great extruded typesetting product, I sometimes see links and email addresses that are different Example:
& lt; P & gt; Here is some random text with an email address & lt; Link & gt; Example & lt; / Link> & Lt; Link & gt; @ Example.com & lt; / Link> And here's a more random text with a URL & lt; Link & gt; Http: //www.< / Link> & Lt; Link & gt; Example.com & lt; / Link> Near the end of the sentence & Lt; / P & gt;
desired output:
& lt; P & gt; Here is some random text with an email address & lt; Email & gt; Example@example.com< / Email & gt; And here's a more random text with url & lt; Ext-link ext-link-type = "uri" xlink: href = "http://www.example.com/" & gt; Http://www.example.com/</ext-link> Near the end of the sentence & Lt; / P & gt;
The whispace between the elements does not appear, which is a blessing.
I can say that I need to use an XSL for each group for a group. P template, but I can not quite see how to include the group through joint text () function as a distinction of email from the URL as a function if you use group-adjacent, String-add (help)
Like
& lt ; Xsl: stylesheet xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" xmlns: xlink = ".org / 1999 / xlink as http: //www.w33" xmlns: xsd = "Http://www.w3.org/2001/XMLSchema" out-result-prefix = "xsd" version = "2.0" & gt; & Lt; Xsl: template match = "p" & gt; & Lt; XSL: Copy & gt; & Lt; Xsl: Select each group = "node ()" group-adjacent = "boolean (auto :: link)" & gt; & Lt; XSL: Select & gt; & Lt; Xsl: when test = "current-group-key ()" & gt; & Lt; Xsl: variable name = "link-text" as = "xsd: string" select = "string-join (current-group (), '')" /> & Lt; XSL: Select & gt; & Lt; Xsl: when test = "match ($ link-text, '^ https ?:' '' ')" & gt; & Lt; Ext-link ext-link-type = "uri" xlink: href = "{$ link-text}" & gt; & Lt; Xsl: select value = "$ link-text" /> & Lt; / Ext-link & gt; & Lt; / XSL: When & gt; & Lt; XSL: otherwise & gt; & Lt; Email & gt; & Lt; Xsl: select value = "$ link-text" /> & Lt; / Email & gt; & Lt; / XSL: otherwise & gt; & Lt; / XSL: Select & gt; & Lt; / XSL: When & gt; & Lt; XSL: otherwise & gt; & Lt; Xsl: apply-select template = "current-group ()" /> & Lt; / XSL: otherwise & gt; & Lt; / XSL: Select & gt; & Lt; / XSL: for each group & gt; & Lt; / XSL: Copy & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;
Comments
Post a Comment