[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: problem with transforming mixed content

Subject: Re: problem with transforming mixed content
From: "Wolfhart Totschnig wolfhart.totschnig@xxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 16 Aug 2020 18:33:01 -0000
Re:  problem with transforming mixed content
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.