XSLT parsing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Walker

    XSLT parsing

    Hi,

    I have an XML file created by a third party in which an element with a
    simple content model has a text value consisting of 2 parts separated by a
    colon, like this

    <link>machine:p ort</link>

    Is XSLT capable of parsing the value of a <link> element, to separately
    extract the portions before and after the colon?

    Regards
    David Walker


  • Andrew Urquhart

    #2
    Re: XSLT parsing

    *David Walker* wrote:[color=blue]
    > I have an XML file created by a third party in which an element with a
    > simple content model has a text value consisting of 2 parts separated
    > by a colon, like this
    >
    > <link>machine:p ort</link>
    >
    > Is XSLT capable of parsing the value of a <link> element, to
    > separately extract the portions before and after the colon?[/color]

    Yes, e.g.:

    <xsl:template match="link">
    <xsl:choose>
    <xsl:when test="contains( ., ':')">
    <xsl:text>Befor e = &quot;</xsl:text>
    <xsl:value-of select="substri ng-before(., ':')"/>
    <xsl:text>&quot ;, after = &quot;</xsl:text>
    <xsl:value-of select="substri ng-after(., ':')"/>
    <xsl:text>&quot ;</xsl:text>
    </xsl:when>
    <xsl:otherwis e>
    <xsl:value-of select="."/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    --
    Andrew Urquhart
    - CIWAS CSS FAQ: www.css.nu/faq/ciwas-aFAQ.html
    - CIWAS Archive: www.tinyurl.com/ysjbm (Google Groups)
    - My reply address is invalid, use: www.andrewu.co.uk/contact/


    Comment

    • Harlan Messinger

      #3
      Re: XSLT parsing

      "David Walker" <david@cs.cf.ac .uk> wrote:
      [color=blue]
      >Hi,
      >
      >I have an XML file created by a third party in which an element with a
      >simple content model has a text value consisting of 2 parts separated by a
      >colon, like this
      >
      ><link>machine: port</link>
      >
      >Is XSLT capable of parsing the value of a <link> element, to separately
      >extract the portions before and after the colon?[/color]

      I suppose a question about XSLT is a bit more relevant to a group on
      style sheets than to a group like, say, rec.knitting... but really,
      what is this doing here?

      --
      Harlan Messinger
      Remove the first dot from my e-mail address.
      Veuillez ôter le premier point de mon adresse de courriel.

      Comment

      • Andrew Urquhart

        #4
        Re: XSLT parsing

        *Harlan Messinger* wrote:[color=blue]
        > *David Walker* wrote:[color=green]
        >> <link>machine:p ort</link>
        >> Is XSLT capable of parsing the value of a <link> element, to
        >> separately extract the portions before and after the colon?[/color]
        >
        > I suppose a question about XSLT is a bit more relevant to a group on
        > style sheets than to a group like, say, rec.knitting... but really,
        > what is this doing here?[/color]

        comp.infosystem s.www.authoring. /stylesheets/

        XSLT; extensible /stylesheet/ language transformations

        CSS and XSLT are both stylesheets.
        To quote the FAQ:

        'At the moment, almost all discussion on this group relates to CSS,
        although that might not always be so. This document does not aim
        to be a complete tutorial in stylesheets or in CSS.'

        Pragmatically speaking comp.text.xml is more applicable at the present
        time, but that is not obvious given this newsgroups dual purpose name.
        Personally I'd prefer to see a comp.text.xml.x slt group, XSLT being a
        subset of XML.
        --
        Andrew Urquhart
        - CIWAS CSS FAQ: www.css.nu/faq/ciwas-aFAQ.html
        - Archive: www.tinyurl.com/ysjbm (Google Groups)
        - My reply address is invalid, use: www.andrewu.co.uk/contact/


        Comment

        • Harlan Messinger

          #5
          Re: XSLT parsing


          "Andrew Urquhart" <useWebsiteInSi gnatureToReply@ spam.invalid> wrote in
          message news:XhDAc.150$ in5.136@newsfe1-win...[color=blue]
          > *Harlan Messinger* wrote:[color=green]
          > > *David Walker* wrote:[color=darkred]
          > >> <link>machine:p ort</link>
          > >> Is XSLT capable of parsing the value of a <link> element, to
          > >> separately extract the portions before and after the colon?[/color]
          > >
          > > I suppose a question about XSLT is a bit more relevant to a group on
          > > style sheets than to a group like, say, rec.knitting... but really,
          > > what is this doing here?[/color]
          >
          > comp.infosystem s.www.authoring. /stylesheets/
          >
          > XSLT; extensible /stylesheet/ language transformations
          >
          > CSS and XSLT are both stylesheets.
          > To quote the FAQ:
          >
          > 'At the moment, almost all discussion on this group relates to CSS,
          > although that might not always be so. This document does not aim
          > to be a complete tutorial in stylesheets or in CSS.'
          >
          > Pragmatically speaking comp.text.xml is more applicable at the present
          > time, but that is not obvious given this newsgroups dual purpose name.
          > Personally I'd prefer to see a comp.text.xml.x slt group, XSLT being a
          > subset of XML.[/color]

          Ah. Understood. I apologize.

          Comment

          • Kimmo J?rvikangas

            #6
            Re: XSLT parsing

            "David Walker" <david@cs.cf.ac .uk> wrote in message news:<caug5e$61 h$1@news.swman. net.uk>...[color=blue]
            > Hi,
            >
            > I have an XML file created by a third party in which an element with a
            > simple content model has a text value consisting of 2 parts separated by a
            > colon, like this
            >
            > <link>machine:p ort</link>
            >
            > Is XSLT capable of parsing the value of a <link> element, to separately
            > extract the portions before and after the colon?
            >
            > Regards
            > David Walker[/color]

            David,

            I suppose there are many ways of achieving that. Here is just one example:

            <?xml version="1.0" encoding="UTF-8"?>
            <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
            <xsl:template match="/">
            <xsl:apply-templates select="link"/>
            </xsl:template>
            <xsl:template match="link">
            <xsl:variable name="machine" select="substri ng-before( . , ':' ) "/>
            <xsl:variable name="port" select="substri ng-after( . , ':' ) "/>
            <xsl:element name="link">
            <xsl:element name="machine">
            <xsl:value-of select="$machin e"/>
            </xsl:element>
            <xsl:element name="port">
            <xsl:value-of select="$port"/>
            </xsl:element>
            </xsl:element>
            </xsl:template>
            </xsl:stylesheet>

            This will transform Your example

            <?xml version="1.0" encoding="UTF-8"?>
            <link>machine:p ort</link>

            To the following:

            <?xml version="1.0" encoding="UTF-8"?>
            <link>
            <machine>machin e</machine>
            <port>port</port>
            </link>

            Is this something like You were after?

            Rgds,

            <kimmo/>

            Comment

            • Jan Roland Eriksson

              #7
              Re: XSLT parsing

              On Fri, 18 Jun 2004 08:47:42 -0400, Harlan Messinger
              <hmessinger.rem ovethis@comcast .net> wrote:
              [color=blue]
              >"David Walker" <david@cs.cf.ac .uk> wrote:[/color]
              [...][color=blue][color=green]
              >>Is XSLT capable of parsing the value...[/color][/color]
              [color=blue]
              >I suppose a question about XSLT is a bit more relevant to a group on
              >style sheets than to a group like, say, rec.knitting... but really,
              >what is this doing here?[/color]

              This NG is not restricted to only discuss CSS, in fact any stylesheet
              technology that is applicable to the www may be discussed here.



              --
              Rex

              Comment

              Working...