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

Re: difficulty using xsl:analyze-string

Subject: Re: difficulty using xsl:analyze-string
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 18 Jul 2018 10:18:51 -0000
Re:  difficulty using xsl:analyze-string
Note that you can achieve what you are doing in 3.0 using the
unparsed-text-lines() function, and in 2.0 it can be done more simply using
tokenize() --

3.0 with expand-text=yes

<xsl:for-each
select="unparsed-text-lines('test.txt')">{.}<br/></xsl:for-each>

2.0:

<xsl:for-each select="tokenize(unparsed-text('test.txt')),
'\r\n'))"><xsl:value-of select="."/><br/></xsl:for-each>

Michael Kay
Saxonica

> On 18 Jul 2018, at 11:06, Mukul Gandhi gandhi.mukul@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Thanks, David for the clarifications.
>
> My modified XSLT transform is following,
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform
<http://www.w3.org/1999/XSL/Transform>"
>                          version="2.0">
>
>     <xsl:output method="xhtml"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>"
>                                                  doctype-public="-//W3C//DTD
XHTML 1.0 Transitional//EN"/>
>
>     <xsl:template match="/">
>         <html xmlns="http://www.w3.org/1999/xhtml
<http://www.w3.org/1999/xhtml>">
>           <head>
>              <title>test</title>
>           </head>
>           <body>
>               <xsl:analyze-string select="unparsed-text('test.txt')"
regex="\r\n">
>                   <xsl:matching-substring>
>                       <br/>
>                   </xsl:matching-substring>
>                   <xsl:non-matching-substring>
>                       <xsl:value-of select="."/>
>                   </xsl:non-matching-substring>
>               </xsl:analyze-string>
>           </body>
>         </html>
>     </xsl:template>
>
> </xsl:stylesheet>
>
> Now I'm getting the result from transform, that I desired.
>
> Its worth mentioning about the regex in the xsl:analyze-string above. I'm
now reading the input for xsl:analyze-string from a text file (the line
delimiter is \r\n on windows), and don't have to write \\ in the regex. And
that makes me understand your point, "that example is matching a newline but
you wanted to match the two characters \n".
>
> On Wed, Jul 18, 2018 at 12:24 PM, David Carlisle d.p.carlisle@xxxxxxxxx
<mailto:d.p.carlisle@xxxxxxxxx> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx
<mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>> wrote:
> > I've some other questions as below, related to xsl:analyze-string,
> >
> > 1) The 1st example here, https://www.w3.org/TR/xslt20/#regex-examples
<https://www.w3.org/TR/xslt20/#regex-examples>
> >
> > specifies regex as \n. That probably got me wrong.
>
> that example is matching a newline but you wanted to match the two
characters \n
>
> >
> > 2) The output I receive, has <br> instead of <br/>. I specified <br/> in
my
> > stylesheet. The output I'm getting might be probably because, I have
> > <xsl:output method="html"/> in the stylesheet.
>
> yes /> is a syntax error in html4 and specified as invalid but ignored in
html5
>
> > When I change output spec to following, <xsl:output method="xhtml"/> I
get
> > <br></br> in the output.
>
>
> you would get <br/> for an empty br in the xhtml namespace in xhtml output
> but you output br in no-namespace.
>
> >
> > When I specify, xsl:output method="xhtml", the following is the complete
> > output I get,
> >
> > <?xml version="1.0" encoding="UTF-8"?><html>
> >    <head>
> >       <title>test</title>
> >    </head>
> >    <body>hello world
> >       <br></br>experimenting with XSLT
> >       <br></br>how are you
> >    </body>
> > </html>
> >
> > Shouldn't an XHTML document begin with something like,
> >
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>">
> >
> > <html xmlns="http://www.w3.org/1999/xhtml
<http://www.w3.org/1999/xhtml>">
>
> to get that (which is a very last-century kind of document markup:-)
> you need to output elements in the http://www.w3.org/1999/xhtml
<http://www.w3.org/1999/xhtml>
> namespace and specify that dtd in the attributes of xsl:output.
>
>
>
>
>
> --
> Regards,
> Mukul Gandhi
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <-list/293509> (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.