Forum Moderators: open
Here is my sample xml code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE myDocType (View Source for full doctype...)>
- <Presentation>
- <something>
<test system="mine" />
</something>
- <Find steps="9" type="great">
- <step id="1">
<param name="title">Hey Now</param>
<param name="actor">Michael</param>
</step>
- <step id="2">
<param name="title">Hey Now</param>
<param name="actor">Michael</param>
</step>
</Find>
</Presentation>
One thing that I would highly recommend is to get yourself a copy of something like <oXygen/>. Think of it as an "IDE" for XML and XSLT development.
W3Schools [w3schools.com] has an X-cellent XSLT tutorial [w3schools.com]. Maybe that can help.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE myDocType (View Source for full doctype...)>
<Presentation>
<something>
<test system="mine" />
</something>
<Find steps="9" type="great">
<step id="1">
<param name="title">Hey Now</param>
<param name="actor">Michael</param>
</step>
<step id="2">
<param name="title">Hey Now</param>
<param name="actor">Michael</param>
</step>
</Find>
</Presentation>
<div id="Presentation">
<ul id="step_1">
<li class="title">1. Hey Now</li>
<li class="actor">Michael</li>
</ul>
<ul id="step_2">
<li class="title">2. Hey Now</li>
<li class="actor">Michael</li>
</ul>
</div>
Thank You!
The XML:
<?xml version="1.0" encoding="UTF-8"?>
<Presentation>
<something>
<test system="mine" />
</something>
<Find steps="9" type="great">
<step id="1">
<param name="title">Hey Now</param>
<param name="actor">Michael</param>
</step>
<step id="2">
<param name="title">Hey Now</param>
<param name="actor">Michael</param>
</step>
</Find>
</Presentation>
The XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="no" method="html" version="4.01" doctype-system="http://www.w3c.org/tr/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN"/>
<xsl:template match="/">
<html>
<head>
<title>test</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="/Presentation/Find[@type='great']">
<xsl:for-each select="step">
<xsl:element name="ul">
<xsl:attribute name="id">
<xsl:value-of select="concat('step_', @id)"/>
</xsl:attribute>
<xsl:element name="li">
<xsl:attribute name="class">title</xsl:attribute>
<xsl:value-of select="param[@name='title']"/>
</xsl:element>
<xsl:element name="li">
<xsl:attribute name="class">actor</xsl:attribute>
<xsl:value-of select="param[@name='actor']"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
[edited by: cmarshall at 4:24 pm (utc) on May 30, 2007]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE myDocType (View Source for full doctype...)>
<Presentation>
<FindError errorSent="This is the error">
</FindError>
</Presentation>
Thanks again,
Ox
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="no" method="html" version="4.01" doctype-system="http://www.w3c.org/tr/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN"/>
<xsl:template match="/">
<html>
<head>
<title>test</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="/Presentation/Find[@type='great']">
<xsl:for-each select="step">
<xsl:element name="ul">
<xsl:attribute name="id">
<xsl:value-of select="concat('step_', @id)"/>
</xsl:attribute>
<xsl:element name="li">
<xsl:attribute name="class">title</xsl:attribute>
<xsl:value-of select="param[@name='title']"/>
</xsl:element>
<xsl:element name="li">
<xsl:attribute name="class">actor</xsl:attribute>
<xsl:value-of select="param[@name='actor']"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:template><xsl:template match="/Presentation/FindError">
<xsl:value-of select="@errorSent"/>
</xsl-template></xsl:stylesheet>
if this error, write this
if this error, write that
<xsl:template match="/Presentation/FindError">
<xsl:if select="@errorSent='nowWay'"/>
write something here
</xsl:if>
<xsl:if select="@errorSent='youLittle'"/>
write something else here
</xsl:if>
</xsl-template>
Am i close?
[edited by: Oxford at 8:32 pm (utc) on June 4, 2007]
XSLT is REAL dumb when it comes to conditional branches. If you want a choice between two or more paths, you need to use xsl:choose
Here are some relevant links:
[w3schools.com...]
[w3schools.com...]
These come from here: [w3schools.com...]
Here's the xml file
<?xml version="1.0" encoding="iso-8859-1"?>
<Presentation version="1.0">
<Find point="1" errorCode="" />
<Find point="2" errorCode="Not_FOUND" />
</Presentation>
-------------------------------------------
Then another xml could be received that has different errors
<?xml version="1.0" encoding="iso-8859-1"?>
<Presentation version="1.0">
<Find point="1" errorCode="Insufficient_INFO" />
<Find point="2" errorCode="" />
</Presentation>
[edited by: Oxford at 1:03 am (utc) on June 5, 2007]
It's fairly complex, but not as complex as XMLSpy or Stylus Studio. It took me a couple of days to figure out. It's a Java app, so is fairly slow on my Mac (but it is cross-platform).
I don't know how I could have learned XSLT without it. All those examples I SMed you were done with it.
If you try correcting my goof (test instead of match), I'll bet your stuff starts working.
The nice thing about <oXygen/> is that it would have immediately told you about my goof. It would have immediately told me as well, so you know I didn't use it to test that.