Mariann Takacs
Mariann Takacs

Reputation: 23

XSLT variable problems

I've just started to get to now xslt, and xml and i can't seem to solve my problem which should be in my homework soon. This is the part i had at the start:

    <p>
    <xsl:text>Date: </xsl:text><xsl:value-of select="/vers/fejlec/ido/ev"/>.
        <xsl:value-of select="/vers/fejlec/ido/honap"/>.
    </p>

The third line gives me a value of 2 In my exercise it should give February instead of 2 (in the example its Hungarian).

So i did this:

   <p>
   <xsl:text>Dátum: </xsl:text><xsl:value-of select="/vers/fejlec/ido/ev"/>.
   <xsl:text> </xsl:text>

   <xsl:variable name="month">
      <xsl:value-of select="/vers/fejlec/ido/honap"/>
   </xsl:variable>

     <xsl:variable name="monthinstring">
       <xsl:choose>
          <xsl:when test="$month=1">januar</xsl:when>
          <xsl:when test="$month=2">februar</xsl:when>
          <xsl:when test="$month=3">marcius</xsl:when>
          <xsl:when test="$month=4">aprilis</xsl:when>
          <xsl:when test="$month=5">majus</xsl:when>
          <xsl:when test="$month=6">junius</xsl:when>
          <xsl:when test="$month=7">julius</xsl:when>
          <xsl:when test="$month=8">augusztus</xsl:when>
          <xsl:when test="$month=9">szeptember</xsl:when>
          <xsl:when test="$month=10">oktober</xsl:when>
          <xsl:when test="$month=11">november</xsl:when>
          <xsl:when test="$month=12">december</xsl:when>
       </xsl:choose>
     </xsl:variable>

     <xsl:text> $monthinstring </xsl:text>

    </p>

Unfortunately i cant print out nor month, nor monthinstring, i tried it more vaw, but it's just not working.

Upvotes: 2

Views: 460

Answers (1)

Daniel Haley
Daniel Haley

Reputation: 52848

Try using xsl:value-of.

Change this:

<xsl:text> $monthinstring </xsl:text>

To this:

<xsl:value-of select="$monthinstring"/>

or this if you need to preserve the white-space before/after $monthinstring:

<xsl:value-of select="concat(' ',$monthinstring,' ')"/>

Upvotes: 1

Related Questions