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

Re: function returning string with string-join()

Subject: Re: function returning string with string-join()
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 6 Aug 2010 09:58:48 -0700
Re:  function returning string with string-join()
> looks interesting, but ...


Yes, I mixed XPath 1.0 and XPath 2.0.

The correct XPath 2.0 expression is:

   concat('NO', ('x',$input)[number($input = (1,2)) +1], '.html')


--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play




On Fri, Aug 6, 2010 at 8:15 AM, Hermann Stamm-Wilbrandt
<STAMMW@xxxxxxxxxx> wrote:
>
> > B  concat('NO', ('x',$input)[($input = (1,2)) +1], '.html')
>
> looks interesting, but ...
>
> $ java -jar ~/Desktop/saxon/saxon9he.jar -xsl:ifn.xsl -s:3.xml
> Error on line 29 of ifn.xsl:
> B XPTY0004: Arithmetic operator is not defined for arguments of types
> (xs:boolean, xs:integer)
> B in built-in template rule
> Transformation failed: Run-time errors were reported
> $ tail -6 ifn.xsl
> <xsl:template match="*">
> B <xsl:variable name="input" select="."/>
> B <xsl:value-of select="concat('NO', ('x',$input)[($input = (1,2)) +1],
> '.html')"/>
> </xsl:template>
>
> </xsl:stylesheet>
> $
>
>
> Mit besten Gruessen / Best wishes,
>
> Hermann Stamm-Wilbrandt
> Developer, XML Compiler, L3
> WebSphere DataPower SOA Appliances
> ----------------------------------------------------------------------
> IBM Deutschland Research & Development GmbH
> Vorsitzender des Aufsichtsrats: Martin Jetter
> Geschaeftsfuehrung: Dirk Wittkopp
> Sitz der Gesellschaft: Boeblingen
> Registergericht: Amtsgericht Stuttgart, HRB 243294
>
>
>
> From: B  B  B  Dimitre Novatchev <dnovatchev@xxxxxxxxx>
> To: B  B  B  B  xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Date: B  B  B  08/06/2010 03:44 PM
> Subject: B  B Re:  function returning string with string-join()
>
>
>
> B concat('NO', ('x',$input)[($input = (1,2)) +1], '.html')
>
>
> --
> Cheers,
> Dimitre Novatchev
> ---------------------------------------
> Truly great madness cannot be achieved without significant intelligence.
> ---------------------------------------
> To invent, you need a good imagination and a pile of junk
> -------------------------------------
> Never fight an inanimate object
> -------------------------------------
> You've achieved success in your field when you don't know whether what
> you're doing is work or play
>
>
>
> On Fri, Aug 6, 2010 at 5:37 AM, ac <ac@xxxxxxxxxxxxx> wrote:
> >
> > Hi,
> >
> > I would have done this one simply as
> > ...
> > <xsl:sequence select="string-join (('NO', if (string($input)) then string
> ($input) else 'x', ',html'), '')"/>
> > ...
> > with the feeling that string-join() is typically faster than concat() and
> string() faster than set operation with predicates, and that the overall
> instruction is easier to read and understand
> >
> > Am I right?
> >
> > Cheers,
> > ac
> >
> >
> >
> >
> >> Am 06.08.2010 um 11:15 schrieb Andrew Welch:
> >>
> >>
> >>>
> >>> When returning atomics (such as xs:string) you should use xs:sequence
> >>> and not xsl:value-of, as value-of will create a text node that then
> >>> gets "atomized" to an atomic.
> >>>
> >>
> >> Thanks for that reminder... xsl:for-each-group and regular expressions
> are well settled in my XSLT2 mind-set, but xsl:sequence is more or less
> ignored.
> >>
> >>
> >>>
> >>> If you didnt have the xsl:message call you could do:
> >>>
> >>> B  B <xsl:function name="my:filename" as="xs:string">
> >>> B  B  B  B <xsl:param name="input" as="xs:integer" />
> >>> B  B  B  B <xsl:sequence select="concat(if ($input = (1,2)) then
('NO1',
> >>> 'NO2')[$input] else 'NOx', '.html')"/>
> >>> B  B </xsl:function>
> >>>
> >>
> >> Yes, if...
> >>
> >> I still try to find the best balance between writing some complex,
> possibly hard to debug multi-line XPath expressions or a tree of XSLT
> elements. Haven't found a general rule for that, and maybe there isn't.
> >>
> >> Thanks a lot,
> >>
> >> - Michael

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.