View Full Version : XML Limitations
kraftomatic
12-24-2003, 04:06 PM
Hey All,
I'm working with an XML page and I have some content which is a few paragraphs long.
How can I in effect, insert two <br> tags to break up the long bit of data in my XML file to separate paragraphs?
Thanks.
XML isn't meant to be formatted. That means that you can't enter a tag that is always a line break. If you're using your own DTD, then I'd suggest wrapping each paragraph in something like <paragraph></paragraph>. If not, just use line breaks.
What language are you using?
kraftomatic
12-24-2003, 07:05 PM
I'm using ASP. I have articles I want to display in a <content> tag. So do break paragraphs, what do I do? From what you suggested, it sounds like I have to do <content1>, <content2>, etc.
Right?
No, what XML based language are you using? That will determine if the DTD allows for <paragraph> style tags, or if you just have to use line breaks.
kraftomatic
12-24-2003, 07:15 PM
Is this what you're talking about?
XML tag: <?xml version="1.0" encoding="ISO-8859-1" ?>
XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="team/rider">
<b><xsl:value-of select="riderName"/></b><br />
Competition No: <xsl:value-of select="riderNo"/><br />
Hometown: <xsl:value-of select="riderTown"/><br />
<br />
<xsl:value-of select="riderBody"/>
<br /><br /><br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
What I mean by XML based language is RSS, SVG, XHTML etc.
But it doesn't look like you're using any of those, it looks like its just a bunch of tags you've made up yourself... correct? In that case, wrap what you want each paragraph to be in <paragraph> and </paragraph>, then a bit of XSLT (assuming the long bit is in riderBody): (edited code in red)<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="team/rider">
<b><xsl:value-of select="riderName"/></b><br />
Competition No: <xsl:value-of select="riderNo"/><br />
Hometown: <xsl:value-of select="riderTown"/><br />
<br />
<xsl:for-each match="riderBody/paragraph">
<p><xsl:value-of select="../paragraph"/></p>
</xsl:for-each>
<br /><br /><br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>So in riderBody, you might have:<paragraph>The first paragraph here</paragraph>
<paragraph>The second paragraph</paragraph>Let me know if that works.
kraftomatic
12-24-2003, 07:30 PM
Ok, so each paragraph will have to have it's own set of tags. That what I initially thought. I'm getting close, but not quite right. Here the XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="team/rider">
<b><xsl:value-of select="riderName"/></b><br />
Competition No: <xsl:value-of select="riderNo"/><br />
Hometown: <xsl:value-of select="riderTown"/><br />
<br />
<xsl:for-each-match="riderBody/paragraph">
<p><xsl:value-of select="../paragraph"/></p>
</xsl:for-each>
<br /><br /><br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I get an error on the "xsl:for-each match=riderBody/paragraph". If I switch the MATCH to SELECT, it works, but only displays the first PARAGRAPH tag.
Any ideas?
My error is actually in this line: <p><xsl:value-of select="../paragraph"/></p>Try swapping out "../paragraph" for "self::" and if that doesn't work, "self".
(Yeah, I'm not too great with XPath ;))
kraftomatic
12-24-2003, 07:37 PM
Eeek. :) For both ..
"The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document. "
Okay, one more... "self::node()" or even "." works I think.
kraftomatic
12-24-2003, 07:42 PM
"The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document. "
Could it be my XML formatting? It looks fine to me:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<team>
<rider>
<riderName>Aaron Bagwell</riderName>
<riderNo>77</riderNo>
<riderTown>Lansing, MI</riderTown>
<riderBody>
<paragraph>In real life, Chuck Seilnacht is a training manager with Ford Motor Company. He's a 50+ racer with 5 years experience racing in most of the lightweight classes. Chuck came to road racing thru a path followed by many: motocross and enduro, followed by street riding, a riding school held at a race facility, a dabble in road racing with a Honda Hawk, and then a commitment (a Ducati!). Chuck's current stable of bikes include a mostly-stock '89 Hawk, a racer-rep '90 Ducati 750, and an F2 track bike.</paragraph>
<paragraph>Highlights of Chuck's career include racing at Road America and Mid-Ohio, and "enjoying the friendship and camaraderie of the Team Witchkraft 'family' and our competition at MGP".</paragraph>
</riderBody>
</rider>
<rider>
<riderName>Chuck Seilnacht</riderName>
<riderNo>508</riderNo>
<riderTown>Dearborn, MI</riderTown>
<riderBody>
<paragraph>In real life, Chuck Seilnacht is a training manager with Ford Motor Company. He's a 50+ racer with 5 years experience racing in most of the lightweight classes. Chuck came to road racing thru a path followed by many: motocross and enduro, followed by street riding, a riding school held at a race facility, a dabble in road racing with a Honda Hawk, and then a commitment (a Ducati!). Chuck's current stable of bikes include a mostly-stock '89 Hawk, a racer-rep '90 Ducati 750, and an F2 track bike.</paragraph>
<paragraph>Highlights of Chuck's career include racing at Road America and Mid-Ohio, and "enjoying the friendship and camaraderie of the Team Witchkraft 'family' and our competition at MGP".</paragraph>
</riderBody>
</rider>
</team>
The problem looks like it's with the XSLT. Let's have that too :thumbsup:
kraftomatic
12-24-2003, 07:45 PM
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="team/rider">
<b><xsl:value-of select="riderName"/></b><br />
Competition No: <xsl:value-of select="riderNo"/><br />
Hometown: <xsl:value-of select="riderTown"/><br />
<br />
<xsl:for-each-match="riderBody/paragraph">
<p><xsl:value-of select="self::node()"/></p>
</xsl:for-each>
<br /><br /><br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Gotcha.<xsl:for-each-match="riderBody/paragraph">needs to be<xsl:for-each match="riderBody/paragraph">Watch the hyphens;)
kraftomatic
12-24-2003, 07:48 PM
I did have it that way. :)
"Attribute 'match' is invalid on 'xsl:for-each'. "
Sorry, it's select="".
I'm a fool.
kraftomatic
12-24-2003, 07:53 PM
select="" didn't work. I used what's below and I'm back where I started (displaying only one paragraph tag) ..
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="team/rider">
<b><xsl:value-of select="riderName"/></b><br />
Competition No: <xsl:value-of select="riderNo"/><br />
Hometown: <xsl:value-of select="riderTown"/><br />
<br />
<xsl:for-each select="riderBody">
<p><xsl:value-of select="self::node()" /></p>
</xsl:for-each>
<br /><br /><br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
You missed the /paragraph. <xsl:for-each select="riderBody/paragraph">
kraftomatic
12-24-2003, 07:55 PM
It works. I could have sworn I tried that too. :)
Thanks for the quick responses. Have a good holiday.
Awesome. I'm shattered. You solved one of my problems (http://www.codingforums.com/showthread.php?s=&threadid=30580), so never mind!
You too!
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.