Subject: Re: [xsl] problem with transforming mixed content From: "Wolfhart Totschnig wolfhart.totschnig@xxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sun, 16 Aug 2020 18:33:01 -0000 |
Dear Mukul, Thank you for your reply! Yesterday, by tweaking the "type (a)" solution proposed by Graydon, I came up with a solution that is basically the same as yours, with the difference that I had not considered the possibility of attributes on the markup elements. I will add that now to my solution, as suggested by your solution. As for getting rid of namespace declarations, that can be done by replacing, in the last template, <xsl:copy> with <xsl:element name="{local-name()}">, as Martin pointed out. Best, Wolfhart On 16.08.20 14:19, Mukul Gandhi gandhi.mukul@xxxxxxxxx wrote: > On Sat, Aug 15, 2020 at 9:33 PM Wolfhart Totschnig > wolfhart.totschnig@xxxxxxxxxxx <mailto:wolfhart.totschnig@xxxxxxxxxxx> > <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx > <mailto: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" > B xmlns:xs="http://www.w3.org/2001/XMLSchema" > B exclude-result-prefixes="xs"> > > B B <xsl:output method="xml" indent="yes"/> > > B B <xsl:template match="title"> > B B B <result> > B B B B B <xsl:variable name="result_pass1" as="element()"> > B B B B B B <temp> > B B B B B B B <xsl:apply-templates select="node()" mode="pass1"/> > B B B B B B </temp> > B B B B B </xsl:variable> > B B B B B <title> > B B B B B B <xsl:copy-of > select="$result_pass1/colon/preceding-sibling::node()"/> > B B B B B </title> > B B B B B <subtitle> > B B B B B B <xsl:copy-of > select="$result_pass1/colon/following-sibling::node()"/> > B B B B B </subtitle> > B B B </result> > B B </xsl:template> > B B <xsl:template match="text()[contains(., ':')]" mode="pass1"> > B B B <xsl:value-of select="lower-case(replace(substring-before(., > ':'), '\s+$', ''))"/> > B B B <colon/> > B B B <xsl:value-of select="lower-case(replace(substring-after(., > ':'), '^\s+', ''))"/> > B B </xsl:template> > B B <xsl:template match="text()" mode="pass1"> > B B B <xsl:value-of select="lower-case(.)"/> > B B </xsl:template> > B B <xsl:template match="*" mode="pass1"> > B B B <xsl:copy> > B B B B B <xsl:copy-of select="@*"/> > B B B B B <xsl:apply-templates mode="pass1"/> > B B B </xsl:copy> > B B </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 > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/2652055> > (by email <>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] problem with transforming, Mukul Gandhi gandhi. | Thread | Re: [xsl] problem with transforming, Dimitre Novatchev dn |
Re: [xsl] Regex in @select Escaping, Eliot Kimber ekimber | Date | Re: [xsl] XSLT2: Grouping mixed con, Keith Burt keithburt |
Month |