Jump to content

Something wrong with stylesheet


Guest adorablepuppy

Recommended Posts

Guest adorablepuppy

The below stylesheet isn't rendering at all. I've looked everywhere for the problem, but can't figure it out. What am I doing wrong?XML file:

<?xml version="1.0"?><?xml-stylesheet href="billfeed.xsl" type="text/xsl"?><feed><money denom="1">	<number>2</number>	<total>2</total></money><money denom="2">	<number>2</number>	<total>4</total></money><money denom="5">	<number>2</number>	<total>10</total></money><money denom="10">	<number>2</number>	<total>20</total></money><money denom="20">	<number>2</number>	<total>40</total></money><money denom="50">	<number>2</number>	<total>100</total></money><money denom="100">	<number>2</number>	<total>200</total></money></feed>

XSL file:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"                 xmlns="http://www.w3.org/1999/xhtml">    <xsl:template match="denom[@type='1']">         <xsl:apply-templates select="money"/>         <xsl:apply-templates select="number"/>         <xsl:apply-templates select="total"/>   </xsl:template>       <xsl:template match="denom[@type='2']">         <xsl:apply-templates select="money"/>         <xsl:apply-templates select="number"/>         <xsl:apply-templates select="total"/>   </xsl:template>      <xsl:template match="denom[@type='5']">         <xsl:apply-templates select="money"/>         <xsl:apply-templates select="number"/>         <xsl:apply-templates select="total"/>   </xsl:template>         <xsl:template match="denom[@type='10']">         <xsl:apply-templates select="money"/>         <xsl:apply-templates select="number"/>         <xsl:apply-templates select="total"/>   </xsl:template>         <xsl:template match="denom[@type='20']">         <xsl:apply-templates select="money"/>         <xsl:apply-templates select="number"/>         <xsl:apply-templates select="total"/>   </xsl:template>         <xsl:template match="denom[@type='50']">         <xsl:apply-templates select="money"/>         <xsl:apply-templates select="number"/>         <xsl:apply-templates select="total"/>   </xsl:template>      <xsl:template match="denom[@type='100']">         <xsl:apply-templates select="money"/>         <xsl:apply-templates select="number"/>         <xsl:apply-templates select="total"/>   </xsl:template>      <xsl:template match="feed">   <html><head><title>BillFeed</title></head>   <body>   <xsl:value-of select="text()"/>   </body>   </html>   </xsl:template>      <xsl:template match="money">     <h1><xsl:value-of select="text()"/></h1>   </xsl:template>      <xsl:template match="number">     <strong><xsl:value-of select="text()"/></strong>   </xsl:template>      <xsl:template match="total">     <FONT COLOR="#FF0000"><xsl:value-of select="text()"/></FONT><br/>   </xsl:template> </xsl:stylesheet>

Link to comment
Share on other sites

The way I see it, you need to replace your XPath expressions in the templates:

<xsl:template match="/feed/money[@denom='1']">

Why is this? Because denom is attribute. There is no "type" attribute in your XML. And the "template" XPath is always absolute(starting with the root of the document ("/") and pointing to the exact location from there).If you have some problems with this, you may consider making the "denom" another element outside the desired output and make something like this:

<?xml version="1.0"?><?xml-stylesheet href="billfeed.xsl" type="text/xsl"?><feed><denom1><money><number>2</number><total>2</total></money></denom1>...</feed>

And a stylesheet with a template like this:

<xsl:template match="/feed/denom1/money>

If the last method I suggested doesn't work, I don't know what will.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...