XSL problem

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

    #1

    XSL problem

    Hello,

    I have an XML document in which uses XSL. I want to translate ANY occurance
    of element "<link>" into "LINK: [value of <link>] :END LINK", no matter what
    its ancestors are. I tried to make a <xsl:template match="link"> but it does
    not seem to work, because the text is not added to the links.
    How do I do this?

    Thanks,

    Kester.


  • Martin Honnen

    #2
    Re: XSL problem



    Kester wrote:

    [color=blue]
    > I have an XML document in which uses XSL. I want to translate ANY occurance
    > of element "<link>" into "LINK: [value of <link>] :END LINK", no matter what
    > its ancestors are. I tried to make a <xsl:template match="link"> but it does
    > not seem to work, because the text is not added to the links.
    > How do I do this?[/color]

    You haven't shown us how your input can look, whether <link> can contain
    other elements for instance, if not you could simply use
    <xsl:template match="link">
    <xsl:text>LIN K: </xsl:text>
    <xsl:value-of select="." />
    <xsl:text> :END LINK</xsl:text>
    </xsl:text>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Kester

      #3
      Re: XSL problem


      "Martin Honnen" <mahotrash@yaho o.de> schreef in bericht
      news:40d56df7@o laf.komtel.net. ..[color=blue]
      >
      >
      > Kester wrote:
      >
      >[color=green]
      > > I have an XML document in which uses XSL. I want to translate ANY[/color][/color]
      occurance[color=blue][color=green]
      > > of element "<link>" into "LINK: [value of <link>] :END LINK", no matter[/color][/color]
      what[color=blue][color=green]
      > > its ancestors are. I tried to make a <xsl:template match="link"> but it[/color][/color]
      does[color=blue][color=green]
      > > not seem to work, because the text is not added to the links.
      > > How do I do this?[/color]
      >
      > You haven't shown us how your input can look, whether <link> can contain
      > other elements for instance, if not you could simply use
      > <xsl:template match="link">
      > <xsl:text>LIN K: </xsl:text>
      > <xsl:value-of select="." />
      > <xsl:text> :END LINK</xsl:text>
      > </xsl:text>
      >[/color]

      OK, here is another example.
      The resource tree looks like this:
      <!--filename: my_website.xml-->
      <page>
      <news>
      <article title="Announce ment">
      <company>Ninten do</company> has announced that it will show its new game
      console next year.
      </article>
      <article title="New spell check language for Office">
      The Fryske Akademy has developed Frisian spell check for
      <company>Micros oft</company> Office XP and Office 2003.
      </article>
      </news>
      <sidebar>
      <item>
      Use <company>HP</company> digital cameras!
      </item>
      <item>
      Driving a <company>Lexu s</company> is a real experience.
      </item>
      </sidebar>
      </page>

      Now, I would like <company> to have <u class="company" >...</u> around it.
      <company> is not used in <article> and <item> only. It's also used
      elsewhere.

      I tried to make this XSL, but it did not work (<company> does not get the
      <u> around it). The other elements work just fine.
      <xsl:stylesheet >
      <xsl:template match="/">
      <xsl:apply-templates/>
      </xsl:template>
      <xsl:template match="page">
      .....
      <body>
      <h1>News</h1>
      <xsl:apply-templates select="news"/>
      <hr/>
      <h1>Sidebar</h1>
      <xsl:apply-templates select="sidebar "/>
      </body>
      .....
      </xsl:template>
      <xsl:template match="/page/news">
      <xsl:apply-templates select="article "/>
      </xsl:template>
      <xsl:template match="/page/news/article">
      <p>
      <b>
      <xsl:value-of select="@title"/>
      </b>
      <br/>
      <xsl:value-of select="."/>
      </p>
      </xsl:template>
      <xsl:template match="/page/sidebar">
      <xsl:apply-templates select="item"/>
      </xsl:template>
      <xsl:template match="/page/sidebar/item">
      <p>
      <xsl:value-of select="."/>
      </p>
      </xsl:template>
      <xsl:template match="company" >
      <u class="company" >
      <xsl:value-of select="."/>
      </u>
      </xsl:template>
      </xsl:stylesheet>

      The question is simple (but the answer might not): How to make the
      <xsl:template match="company" > work as stated above?

      Kester.


      Comment

      • Martin Honnen

        #4
        Re: XSL problem



        Kester wrote:

        [color=blue]
        > The resource tree looks like this:
        > <!--filename: my_website.xml-->
        > <page>
        > <news>
        > <article title="Announce ment">
        > <company>Ninten do</company> has announced that it will show its new game
        > console next year.
        > </article>
        > <article title="New spell check language for Office">
        > The Fryske Akademy has developed Frisian spell check for
        > <company>Micros oft</company> Office XP and Office 2003.
        > </article>
        > </news>
        > <sidebar>
        > <item>
        > Use <company>HP</company> digital cameras!
        > </item>
        > <item>
        > Driving a <company>Lexu s</company> is a real experience.
        > </item>
        > </sidebar>
        > </page>
        >
        > Now, I would like <company> to have <u class="company" >...</u> around it.
        > <company> is not used in <article> and <item> only. It's also used
        > elsewhere.
        >
        > I tried to make this XSL, but it did not work (<company> does not get the
        > <u> around it). The other elements work just fine.
        > <xsl:stylesheet >
        > <xsl:template match="/">
        > <xsl:apply-templates/>
        > </xsl:template>
        > <xsl:template match="page">
        > ....
        > <body>
        > <h1>News</h1>
        > <xsl:apply-templates select="news"/>
        > <hr/>
        > <h1>Sidebar</h1>
        > <xsl:apply-templates select="sidebar "/>
        > </body>
        > ....
        > </xsl:template>
        > <xsl:template match="/page/news">
        > <xsl:apply-templates select="article "/>
        > </xsl:template>
        > <xsl:template match="/page/news/article">
        > <p>
        > <b>
        > <xsl:value-of select="@title"/>
        > </b>
        > <br/>
        > <xsl:value-of select="."/>
        > </p>
        > </xsl:template>
        > <xsl:template match="/page/sidebar">
        > <xsl:apply-templates select="item"/>
        > </xsl:template>
        > <xsl:template match="/page/sidebar/item">
        > <p>
        > <xsl:value-of select="."/>[/color]

        Here is the problem, you simply take the value here but you have
        subelements you need to process so use
        <xsl:apply-templates />
        instead of <xsl:value/>.

        [color=blue]
        > <xsl:template match="company" >
        > <u class="company" >
        > <xsl:value-of select="."/>
        > </u>
        > </xsl:template>[/color]

        That template is fine you only need to make sure that processing reaches
        it by using <xsl:apply-templates> in the elements containing company.
        --

        Martin Honnen
        http://JavaScript.FAQTs.com/

        Comment

        • Kester

          #5
          Re: XSL problem


          "Martin Honnen" <mahotrash@yaho o.de> schreef in bericht
          news:40d5aa4a$1 @olaf.komtel.ne t...
          [color=blue]
          > That template is fine you only need to make sure that processing reaches
          > it by using <xsl:apply-templates> in the elements containing company.[/color]

          Thank you very much!

          Kester.


          Comment

          Working...