how do I match an replace text with XSL

Discussion in 'XML' started by Alois Treindl, Jul 18, 2006.

  1. A simple XSL question from a newbie:

    In an xml document which I transform via xsl into html output, I have
    some text which I want to be suppressed.

    The tags looks like this
    <anchor_ref name="#B4">I. Introduction - page 4 </anchor_ref>
    <anchor_ref name="#B4">II. Childhood - page 24 </anchor_ref>
    <anchor_ref name="#B4">I. Later - page 42 </anchor_ref>

    I want to define an xsl rule which gets rid of the page numbers which
    make no sense in the html version.

    I.e. anything fitting the pattern ' - page NN '
    where NN is a single or double digit number should be replaced by nothing.

    How would this XSL rule look?

    A later complication will be that the word 'page' can also appear in
    other languages, e.g. 'Seite 4', 'pagina 4' etc.
     
    Alois Treindl, Jul 18, 2006
    #1
    1. Advertising

  2. Use the substring-before() function.

    Cheers,
    Dimitre Novatchev

    "Alois Treindl" <my_real_firstname@my_real_lastname.com> wrote in message
    news:e9iluo$3dp$-plus.net...
    >A simple XSL question from a newbie:
    >
    > In an xml document which I transform via xsl into html output, I have some
    > text which I want to be suppressed.
    >
    > The tags looks like this
    > <anchor_ref name="#B4">I. Introduction - page 4 </anchor_ref>
    > <anchor_ref name="#B4">II. Childhood - page 24 </anchor_ref>
    > <anchor_ref name="#B4">I. Later - page 42 </anchor_ref>
    >
    > I want to define an xsl rule which gets rid of the page numbers which make
    > no sense in the html version.
    >
    > I.e. anything fitting the pattern ' - page NN '
    > where NN is a single or double digit number should be replaced by nothing.
    >
    > How would this XSL rule look?
    >
    > A later complication will be that the word 'page' can also appear in other
    > languages, e.g. 'Seite 4', 'pagina 4' etc.
     
    Dimitre Novatchev, Jul 18, 2006
    #2
    1. Advertising

  3. Alois Treindl wrote:


    > In an xml document which I transform via xsl into html output, I have
    > some text which I want to be suppressed.
    >
    > The tags looks like this
    > <anchor_ref name="#B4">I. Introduction - page 4 </anchor_ref>
    > <anchor_ref name="#B4">II. Childhood - page 24 </anchor_ref>
    > <anchor_ref name="#B4">I. Later - page 42 </anchor_ref>
    >
    > I want to define an xsl rule which gets rid of the page numbers which
    > make no sense in the html version.
    >
    > I.e. anything fitting the pattern ' - page NN '
    > where NN is a single or double digit number should be replaced by nothing.


    XSLT 1.0/XPath 1.0 are not very powerful when it comes to string
    manipulation, string matching, string replacement.
    You could write an XSLT template
    <xsl:template match="text()[contains(. 'page')]">
    to match text nodes which contain the string 'page' but there are no
    ways to do regular expression pattern matching for two digits behind 'page'.


    So unless you can use XSLT/XPath 2.0 which has regular expression
    support you have a lot of code to write in XSLT/XPath 1.0. It might help
    to (re)use existing solutions for string replacement, see the replace
    and tokenize solutions in EXSLT
    <http://www.exslt.org/str/index.html>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jul 18, 2006
    #3
  4. Martin Honnen wrote:
    >
    >
    > Alois Treindl wrote:
    >
    >
    >> In an xml document which I transform via xsl into html output, I have
    >> some text which I want to be suppressed.
    >>
    >> The tags looks like this
    >> <anchor_ref name="#B4">I. Introduction - page 4 </anchor_ref>
    >> <anchor_ref name="#B4">II. Childhood - page 24 </anchor_ref>
    >> <anchor_ref name="#B4">I. Later - page 42 </anchor_ref>
    >>
    >> I want to define an xsl rule which gets rid of the page numbers which
    >> make no sense in the html version.
    >>
    >> I.e. anything fitting the pattern ' - page NN '
    >> where NN is a single or double digit number should be replaced by
    >> nothing.

    >
    > XSLT 1.0/XPath 1.0 are not very powerful when it comes to string
    > manipulation, string matching, string replacement.
    > You could write an XSLT template
    > <xsl:template match="text()[contains(. 'page')]">
    > to match text nodes which contain the string 'page' but there are no
    > ways to do regular expression pattern matching for two digits behind
    > 'page'.
    >
    >
    > So unless you can use XSLT/XPath 2.0 which has regular expression
    > support you have a lot of code to write in XSLT/XPath 1.0. It might help
    > to (re)use existing solutions for string replacement, see the replace
    > and tokenize solutions in EXSLT
    > <http://www.exslt.org/str/index.html>
    >



    I use xsltproc, which says:
    Using libxml 20510, libxslt 10033 and libexslt 722
    xsltproc was compiled against libxml 20510, libxslt 10033 and libexslt 722
    libxslt 10033 was compiled against libxml 20510
    libexslt 722 was compiled against libxml 20510

    I don't know whether this is XSLT/XPath 1.0 or 2.0.

    If it is 2.0, I would of course be very happy to get explicit xsl rules.

    So far, we have built a crutch and do the filtering with good old sed.
     
    Alois Treindl, Jul 18, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ray Tayek
    Replies:
    3
    Views:
    518
    Ray Tayek
    Nov 30, 2003
  2. Replies:
    1
    Views:
    3,612
    A. Bolmarcich
    May 27, 2005
  3. John Gordon
    Replies:
    13
    Views:
    490
    Ian Kelly
    Dec 20, 2011
  4. Replies:
    3
    Views:
    175
    Brian McCauley
    Sep 12, 2005
  5. mscir
    Replies:
    0
    Views:
    316
    mscir
    Oct 12, 2005
Loading...

Share This Page