Subject: Re: [xsl] problem with transforming mixed content From: "Mukul Gandhi gandhi.mukul@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sun, 16 Aug 2020 09:19:27 -0000 |
On Sat, Aug 15, 2020 at 9:33 PM Wolfhart Totschnig wolfhart.totschnig@xxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > But I am still curious: What would an approach of type (a) look like in my > case? It seems to me that implementing this approach would again face the > original problem: "turning the punctuation into markup" sounds like a > description of the original problem. > I've come up with following seemingly correct XSLT transform, that uses approach of type (a) suggested within this thread, <xsl:stylesheet version="3.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform" xmlns:xs=" http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"> <xsl:output method="xml" indent="yes"/> <xsl:template match="title"> <result> <xsl:variable name="result_pass1" as="element()"> <temp> <xsl:apply-templates select="node()" mode="pass1"/> </temp> </xsl:variable> <title> <xsl:copy-of select="$result_pass1/colon/preceding-sibling::node()"/> </title> <subtitle> <xsl:copy-of select="$result_pass1/colon/following-sibling::node()"/> </subtitle> </result> </xsl:template> <xsl:template match="text()[contains(., ':')]" mode="pass1"> <xsl:value-of select="lower-case(replace(substring-before(., ':'), '\s+$', ''))"/> <colon/> <xsl:value-of select="lower-case(replace(substring-after(., ':'), '^\s+', ''))"/> </xsl:template> <xsl:template match="text()" mode="pass1"> <xsl:value-of select="lower-case(.)"/> </xsl:template> <xsl:template match="*" mode="pass1"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates mode="pass1"/> </xsl:copy> </xsl:template> </xsl:stylesheet> This is again a two pass solution. In the first pass, the ':' character is transformed into the markup <colon/>, and the second pass (using the first pass's result) produces the final result. As also suggested, the above XSLT transform can also handle any number of differently named markups (that can optionally have any number of attributes) before and after the ':' character. I've also yet not considered XML namespaces mentioned within the use case. -- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] problem with transforming, Wolfhart Totschnig w | Thread | Re: [xsl] problem with transforming, Wolfhart Totschnig w |
Re: [xsl] problem with transforming, Wolfhart Totschnig w | Date | [xsl] Regex in @select Escaping Puz, Eliot Kimber ekimber |
Month |