Problem with text not being effected in a list

Problem with text not being effected in a list

Post by Thomas Thale » Sat, 05 Oct 2002 23:41:40



Hello People,
I tried a few things but I have a problem that i can not solve... maybe
someone can advice me?

The problem is that I want to change the look of the text inside the P
element wich is contained in the Special element. The attribute should
say what way it has to be changed.

Ok.. what I can get to work is test file in xsl, for e..g I can change
the color of the text in the normal P element, also in the list.
Changing the Special/P element is something a cannot get working... :(

so in Pseudocode it would look like


      IF Content-type= Italic THEN
      make text Italic
      ENDIF
      IF Content-type= Bold Then
      make text Bold
      ENDIF
      etc.....
ELSE
Just normal text
ENDIF

I have an XML file looking like this ( small part only)

<List Ordered="Yes">
<Li>
<Special Content-type="Italic">
<P>Introduction</P>
</Special>
<P> (this lesson). We consider the tools that we are going to
use in this course, write a small Java program and make it run. </P>
</Li>

and the following xsl file:


<xsl:for-each select="Li">
<xsl:if test="position()=1">
<xsl:text disable-output-escaping="yes">&lt;ol
type="1"&gt;</xsl:text>
</xsl:if>
<li>
<xsl:value-of select="P"/>
</li>
<xsl:if test="position()=last()">
<xsl:text disable-output-escaping="yes">&lt;/ol&gt;</xsl:text>
</xsl:if>
<br/>
<br/>
</xsl:for-each>
</xsl:template>

<xsl:template match="P">
<xsl:if test="parent::Special">

<em><xsl:value-of select="."/></em>
</xsl:if>
</xsl:if>

<xsl:if test="not(parent::Special)">
<xsl:value-of select="."/>
</xsl:if>
</xsl:template>

Thanks,

Thomas,
Exchange Student (from Holland) in Thessalonniki, Greece :)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

 
 
 

Problem with text not being effected in a list

Post by Henrik Motake » Sun, 06 Oct 2002 00:12:13



> The problem is that I want to change the look of the text inside the P
> element wich is contained in the Special element. The attribute should
> say what way it has to be changed.

Wouldn't it be easiest to define one template for each Content-type,
and one for non-Special <P>s?


    <em><xsl:apply-templates/></em>
    <!-- or whatever, you might want to create a <p> element
         around the <em>, for example -->
  </xsl:template>


    ...
  </xsl:template>

  <xsl:template match="P">
    ...
  </xsl:template>


    <ol type="1">
      <xsl:apply-templates select="Li"/>
    </ol>
  </xsl:template>

The default templates will be applied to all of <Li>s descendants,
finding the right template to apply. There is not much use in
reinventing the template matching with <xsl:if> (and you might have
been better served with <xsl:choose> anyway. Also, there is no point
in creating the <ol> element with disable-output-escaping - don't use
it unless you absolutely have to, it's too easy to create
non-wellformed documents by mistake.)

Regards
Henrik