|
Well, what's the format of the source XML? If you write your own XML format then you should be able to write your own XSL transform to turn it into text.
I wrote an article[^] that used the XMI format which can be exported by a lot of UML diagramming tools. I then converted that into CodeDom, which I think is more useful than a stylesheet because I can convert to VB, C#, or JScript.
Another cool way to do it is to use CodeSmith[^]. It can read a database schema and create classes, stored procedures, etc. The templates used in CodeSmith work a lot like ASP pages and can also have code-behinds. So they're much easier to use than XSL.
|
|
|
|
|
I'm trying to add some XSL to my XML page. I have checked my CXSL code with XMLSpy and it's well formed. I insert the following line which works fine when I open up the XML file on it's own:
However, when I try openoing up my whole html document, it doesn't work. The table comes up, but there's no colour, border adjustments, nothing! Why is this? I've checked websites and even a book and they all say this code is correct. I want to get my XSL inside the HTML file but for some reason it isn't letting me. I have to hand this work in tomorrow morning so please help me quick!
|
|
|
|
|
The code didn't show up for some reason, i'll try again:
"?"
Please help me!
|
|
|
|
|
This is rediculous, how do I get the code to show up? It's the "xml stylesheet type=text/xsl href="CDCatalog.xsl". I'm hoping as i've written it normally this time without any brackets it'll show up?
|
|
|
|
|
Some expert must be there to help me surely? I'm really panicking over this. Even if you don't think you're right could someone please suggest something?
|
|
|
|
|
while posting click the ignore html tags check box at the bottom of the post
hope it works
|
|
|
|
|
When you post XML/(X)HTML documents, you need to change all the < to < and > to >. Or, you can just check the "Ignore HTML tags in this message (good for code snippets)" checkbox below the textarea. If you post it again, I can take a look at it and maybe help you.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
<?xml-stylesheet type="text/xsl" href="CDCatalog.xsl"?>
This code won't work for my XML file. i don't know why. The actual table is being displayed fine but it isn't aligned to the middle and the text and border should be in colour. Hope you can help!
|
|
|
|
|
Okay, lots of things.
First, using an XML datasource in IE to populate a table (as in your HTML file) will not apply the stylesheet to the XML data. Instead, you must put your styles in the TABLE with the DATASRC.
Second, using what you posted, your stylesheet has some incorrect values in it. Remember, XML is case-sensitive. Thus, "cd" and "CD" are different. Here's a stylesheet that will do what you want for the XML file.
XSL file
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="/CATALOG/CD">
<tr>
<td><xsl:value-of select="./TITLE"/></td>
<td><xsl:value-of select="./ARTIST"/></td>
<td><xsl:value-of select="./COUNTRY"/></td>
<td><xsl:value-of select="./COMPANY"/></td>
<td><xsl:value-of select="./PRICE"/></td>
<td><xsl:value-of select="./YEAR"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Thank you Curtis, the code works fine I should be alright now but i'll let you know if I have anymore problems. Thanks for your help!
|
|
|
|
|
'T was my pleasure. Happy coding!
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Curtis, in case you've gone out and i'm not here by the time you reply i'll post up my whole code. Maybe you could see what's wrong?
My html file is:
<title>Untitled Document
<xml src="A:\CDCatalog.xml" id="xmldso" async="false">
Title | Artist | Country | Company | Price | Year |
---|
| | | | | |
|
|
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body bgcolour="#FFFFFF" text="#000000">
<xml src="A:\CDCatalog.xml" id="xmldso" async="false">
</xml>
<table datasrc="#xmldso" width="100%" border="1">
<thead>
<th>Title</th>
<th>Artist</th>
<th>Country</th>
<th>Company</th>
<th>Price</th>
<th>Year</th>
</thead>
<tr align="left">
<td><span datafld="TITLE"></span></td>
<td><span datafld="ARTIST"></span></td>
<td><span datafld="COUNTRY"></span></td>
<td><span datafld="COMPANY"></span></td>
<td><span datafld="PRICE"></span></td>
<td><span datafld="YEAR"></span></td>
</tr></table>
</body>
</html>
|
|
|
|
|
</CD>
- <CD>
<TITLE>Voodoo Child</TITLE>
<ARTIST>Jimmy Hendrix</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>9.99</PRICE>
<YEAR>2000</YEAR>
</CD>
<CD>
<TITLE>The Wall</TITLE>
<ARTIST>Pink Floyd</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>A and M</COMPANY>
<PRICE>14.99</PRICE>
<YEAR>1986</YEAR>
</CD>
<CD>
<TITLE>London Calling</TITLE>
<ARTIST>Clash</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Virgin</COMPANY>
<PRICE>13.99</PRICE>
<YEAR>1984</YEAR>
</CD>
<CD>
<TITLE>Hotel California</TITLE>
<ARTIST>The Eagles</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Island</COMPANY>
<PRICE>9.99</PRICE>
<YEAR>1990</YEAR>
</CD>
<CD>
<TITLE>Shout</TITLE>
<ARTIST>Tears For Fears</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>12.99</PRICE>
<YEAR>1984</YEAR>
</CD>
<CD>
<TITLE>Blue Monday</TITLE>
<ARTIST>New Order</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>A and M</COMPANY>
<PRICE>10.99</PRICE>
<YEAR>1987</YEAR>
</CD>
<CD>
<TITLE>Singles</TITLE>
<ARTIST>The Smiths</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Virgin</COMPANY>
<PRICE>12.99</PRICE>
<YEAR>1996</YEAR>
</CD>
<CD>
<TITLE>She Sells Sanctuary</TITLE>
<ARTIST>The Cult</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Island</COMPANY>
<PRICE>14.99</PRICE>
<YEAR>1989</YEAR>
</CD>
</CATALOG>
|
|
|
|
|
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="Title"/></td>
<td><xsl:value-of select="Artist"/></td>
<td><xsl:value-of select="Country"/></td>
<td><xsl:value-of select="Company"/></td>
<td><xsl:value-of select="Price"/></td>
<td><xsl:value-of select="Year"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
|
Hi,
When I try to open an xml with the following it fails if the xml file contains certain characters. At this point it is failing on on the "&" character.
Is there a way to have these characters ignored?
Dim xdoc As XPathDocument = New XPathDocument(filePath)
Thanks,
Zenu
|
|
|
|
|
XML has five predefined entities that cannot exist in parsed character data. These are:So, if you have an XML file with one of those in the parsed character data, then you do not have a valid XML document. For example:
Correct XML
<a>Bob & Jane went to "work"</a>
Incorrect XML
<a>Bob & Jane went to "work"</a> XML does allow for a way "around" this, of course.
<a><![CDATA[Bob & Jane went to "work"]]></a> The CDATA means unparsed character data, in its raw state. Try using that.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hi Curtis,
Thanks for getting back to me. The following is a sample of my xml file. I am not sure where in it I would add the CDATA. I tried <file name="<![CDATA["File" with="" &="" character.doc"]]=""> but it did not seem to like it very much.
<vfs path="efmROOT">
<file name="File Name with & character.doc" size="29" origpath="\\server1\g$\data\data\File Name with & character.doc">
Thanks
|
|
|
|
|
Next time, check the "Ignore HTML tags in this message (good for code snippets)" checkbox so that the XML shows up! <smile />
Okay, I didn't understand that the string existed in a tag's attribute. So, just replace the & with a &. Like:
<myTag attribute1="this & that" />
The CDATA thing only works for tag values, that is, entries between open and close tags. Never, ever in attribute values.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Thank you. It works fine now.
|
|
|
|
|
Excellent! Happy coding.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hi,
I am new to XML and C#. I want to load this XML via the below code to an XmlDocument but it returns an Error which I don't know how to handle it. Here is the XML:
<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="urn:iana:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iana:xml:ns:epp-1.0 epp-1.0.xsd">
<response>
<result code="1000">
<msg lang="en-US">Command completed successfully</msg>
</result>
<resData>
<contact:creData>
<contact:id>Epp1464</contact:id>
</contact:creData>
</resData>
<trID>
<clTRID>CrtContact0031</clTRID>
<svTRID>CrtContact0031-OLNIC-SRV</svTRID>
</trID>
<chksum>979170f7c148e945e352c7d155da8ac2</chksum>
</response>
</epp>
And here is my code. Actually I need also to know how to get the <contact:id> and <result> node bvalue and attribue.
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strXMLSrc);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Please help.
Samy
-- modified at 8:33 Wednesday 11th January, 2006
|
|
|
|
|
Anybody help me!
My wordml has the following styles:
w:p[w:pPr/w:pStyle[@w:val='authors']]
w:r[w:rPr/w:rStyle[@w:val='csfname']
w:r[w:rPr/w:rStyle[@w:val='csmidname']
w:r[w:rPr/w:rStyle[@w:val='cssurname']
w:p[w:pPr/w:pStyle[@w:val='affiliation']]
w:r[w:rPr/w:rStyle[@w:val='orgname']
w:r[w:rPr/w:rStyle[@w:val='city']
w:r[w:rPr/w:rStyle[@w:val='country']
I want to group the 3 different character styles under
"author" and another 3 different character styles
under "affiliation" and also group 2 paragraph styles
-- authors and affilition under authorgrp. I want the
output like:
<authorgrp>
<author>
<fname>aaaaaaaaa</fname>
<midname>cccccccc</midname>
<surname>bbbbbbbb</surname>
</author>
<affiliation>
<orgname>mmmmmmmm</orgname>
<city>nnnnnnnnn</city>
<country>ooooooooo</country>
</affiliation>
</authorgrp>
|
|
|
|
|
Summary Question: How can I do pointer fix uping using XML Serialization?
I'm getting tripped up over one idea when performming XML serialization.
Lets say I have a simple class structure where Students have Teachers.
<br />
class Teacher<br />
{<br />
public string name;<br />
}<br />
<br />
class Student<br />
{<br />
public Teacher mTeacher;<br />
}<br />
<br />
main<br />
{<br />
Teacher teacher = new Teacher();<br />
teacher.name = "Mr Smith";<br />
<br />
Student [] students = new Student[2];<br />
<br />
students[0] = new Student();<br />
students[1] = new Student();<br />
<br />
students[0].mTeacher = teacher;<br />
students[1].mTeacher = teacher;<br />
<br />
...<br />
<br />
SERIALIZE students[]<br />
...<br />
DESERIALIZE students[]<br />
<br />
}<br />
What I'm finding is that when I serialize/deserialize, I'll find that each student has their own unique teacher "Mr Smith" rather than both students sharing the same teacher.
When I do this kind of serialization using a BinaryFormatter I find that the teacher is not created twice and that the serializer realizes that this object has already been serialized and essentially stores a pointer and when the object is serialized, that pointer is fixed up.
Summary Question: How can I do pointer fix uping using XML Serialization?
|
|
|
|
|
I have an XmlDocument that I use with an XmlTransform that generates some HTML with a javascript section. The javascript has an if ( a < b){} in it, but that is really confusing the transform processor.
I found a document that suggested that the correct way is to use this construction:
<xsl:text disable-output-escaping="yes"><</xsl:text> However, all that happens is that it confuses the parser. I get the following exception when XmlTransform.Load() is called: This is an unexpected token. The expected token is 'NAME'. Line 23, position 63.
Other options I've tried tend to output < which causes a runtime error when that piece of javascript is run.
Does anyone have any ideas of how to fix this?
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|