Jump to content

displaying elements within elements


rumkarma

Recommended Posts

Hi guys,Have a question for u guys. This might be simple for the seniors but I'm just starting, so pls help me out.This is my XML code :

<?xml version="1.0" encoding="ISO-8859-1"?><!-- Edited by XMLSpy® --><catalog>	<cd>		<title>Empire Burlesque</title>		<artist>Bob Dylan</artist>		<country>USA</country>		<company>Columbia</company>		<price>10.90</price>		<year>1985</year>	</cd>	<cd>		<title>Hide <small-caps> your </small-caps> heart</title>		<artist>Bonnie Tyler</artist>		<country>UK</country>		<company>CBS Records</company>		<price>9.90</price>		<year>1988</year>	</cd>	<cd>		<title>Greatest Hits</title>		<artist>Dolly Parton</artist>		<country>USA</country>		<company>RCA</company>		<price>9.90</price>		<year>1982</year>	</cd>		<cd>		<title>Unchain my heart</title>		<artist>Joe Cocker</artist>		<country>USA</country>		<company>EMI</company>		<price>8.20</price>		<year>1987</year>	</cd></catalog>

This is the corresponding XSLT code:<

?xml version="1.0" encoding="ISO-8859-1"?><!-- Edited by XMLSpy® --><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">  <html>  <body>		<xsl:apply-templates select="/catalog/cd/title"/><br/>		<xsl:apply-templates select="/catalog/cd/artist"/>  </body>  </html></xsl:template><xsl:template match="/catalog/cd/title"><xsl:value-of select="text()"/><xsl:choose><xsl:when test="child::small-caps"><xsl:apply-templates select="/catalog/cd/title/small-caps"/></xsl:when></xsl:choose><br/></xsl:template><xsl:template match="/catalog/cd/artist"><xsl:value-of select="text()"/><br/></xsl:template><xsl:template match="/catalog/cd/title/small-caps"><xsl:value-of select="text()"/><xsl:value-of select="../text()"/></xsl:template></xsl:stylesheet>

And the result is as below :

<html><body>Empire Burlesque<br>Hide  your Hide <br>Greatest Hits<br>Unchain my heart<br><br>Bob Dylan<br>Bonnie Tyler<br>Dolly Parton<br>Joe Cocker<br></body></html>

As you can see, the text after the <small-caps> tag is not being displayed. Pls help me out with the coreect code to do it. Thx in advance.

Link to comment
Share on other sites

Sorry about that. I wanted my result to be like this :

<html><body>Empire Burlesque<br>Hide  your heart <br>Greatest Hits<br>Unchain my heart<br><br>Bob Dylan<br>Bonnie Tyler<br>Dolly Parton<br>Joe Cocker<br></body></html>

and I've since realized that this is a stupid question.but is there a way to display the text within <small-caps> tag in caps and the remaining text as it is?

Link to comment
Share on other sites

If you transform to HTML with CSS you can use font-variant: small-caps to suggest to the user agent to render text in small caps:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">  <html>  <body>		<xsl:apply-templates select="/catalog/cd/title"/><br/>		<xsl:apply-templates select="/catalog/cd/artist"/>  </body>  </html></xsl:template><xsl:template match="cd/title">  <xsl:apply-templates/>  <br/></xsl:template><xsl:template match="cd/artist">  <xsl:apply-templates/>  <br/></xsl:template><xsl:template match="cd/title/small-caps">  <span style="font-variant: small-caps;">	<xsl:apply-templates/>  </span></xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...