[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: "Mukul Gandhi gandhi.mukul@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 16 Aug 2020 09:19:27 -0000
Re:  problem with transforming mixed content
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

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.