Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsl mark up problem 1

Status
Not open for further replies.

simonchristieis

Programmer
Joined
Jan 10, 2002
Messages
1,144
Location
GB
I have an xml file:

<Paragraph>
Zamora tells <I>Petroleum Economist</I> that foreign and private-sector.
</Paragraph>

and I want to mark it up using the (deprecated - i know) italic tag.

but although I can loop through the Paragraph elements, I can't get the page to mark up with the <I> element in the right place.

Using this code ignores the I tag as it should, what I am trying to do is mark up the entire paragraph using the child elements as mark up instructions.

<xsl:for-each select="Paragraph">
<xsl:if test="normalize-space(text())">
<xsl:value-of select="."/><BR/><BR/>
</xsl:if>
</xsl:for-each>

any ideas ?

Simon


 
<xsl:value-of ...> only gives you the value of the node and its children. What you want is to preserve the <I> tags, that is to insert a node with tag "I" in your result.
You could use <xsl_copy ...> to do that:
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
   <xsl:output method="html" encoding="Windows-1252" />
   <xsl:template match="/">
      <html>
         <body>
            <xsl:for-each select="//Paragraph">
               <xsl:apply-templates />
               <BR />
               <BR />
            </xsl:for-each>
         </body>
      </html>
   </xsl:template>

   <xsl:template match="I">
      <xsl:copy-of select="." />
   </xsl:template>
</xsl:stylesheet>
 
Thanks - that hit the spot.

My final code:

<xsl:for-each select="Paragraph">
<xsl:apply-templates />
<xsl:if test="normalize-space(text())">
<xsl:value-of select="."/><BR/><BR/>
</xsl:if>
</xsl:for-each>

<xsl:template match="I">
<I><xsl:value-of select="."/></I>
</xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top