|
Hi,
I tried the following in XML
<code><?xml version="1.0" encoding="UTF-8" standalone="no"?></code>
And the following in XSD
<code><xsl:output method="html" indent="yes" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/></code>
thanks,.
Hariharan C.
|
|
|
|
|
here is a dummy example I made to show the principle.
neither dtd nor schema is provided and the xsl is
connected in the xml to allow you to open the xml in
ie and see the resulting (minimalistic) web page.
rem: the location of my xsl file is hard coded in
C:\Temp\
both files are saved on disk in utf-8
txt.xml:
<?xml version="1.0" encoding="UTF-8"?&ft;
<?xml-stylesheet type="text/xsl" href="C:\Temp\dummy.xsl"?>
<bla>üöä</bla>
dummy.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="iso-8859-1" indent="yes" omit-xml-declaration="yes" media-type="text/html"/>
<xsl:template match="bla">
<html>
<body>
<xsl:value-of select="."/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
hope this helps
Erik
|
|
|
|
|
Thanks Erik,
I tried this too, resulting two junk characters instead of Unicode character. Do I need to install any fonts for this?
Regards,
Hariharan C.
|
|
|
|
|
you have to take care that the files saved on disk are saved in utf-8 format and not in ansi
(most text editors will allow you to change)
Erik
|
|
|
|
|
Sometimes when you save a Unicode document, it places a couple of extra bytes at the beginning of the XML file. I usually delete those bytes, and everything seems to work after that.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I am using the SQLXML managed classes to generate some XML from a SQL Server database, specifying a reference to an XSL stylesheet for my SqlXmlCommand object to transform the raw XML returned from the database. My stylesheet is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="Root">
<xsl:element name="ParameterTemplates">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="Root/*">
<xsl:element name="ParameterTemplate">
<xsl:for-each select="@*">
<xsl:element name="Parameter">
<xsl:attribute name="Name"><xsl:value-of select="name()"/></xsl:attribute>
<xsl:attribute name="Value"><xsl:value-of select="."/></xsl:attribute>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
I have added the attribute indent="yes" to my <xsl:output> element which has the effect of formatting the output with line feeds. This is fine, however I would like to "prettily" indent the output in a similar manner to that which can be produced using the XmlTextWriter. What is the best way of achieving this? Can I modify my stylesheet to indent the nodes? Or would I have to perform some post-processing of the output in my .NET code to achieve this, perhaps using a combination of an XmlTextReader and XmlTextWriter?
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
-- modified at 18:05 Thursday 1st November, 2007
|
|
|
|
|
pmarfleet wrote: Can I modify my stylesheet to indent the nodes?
Yes and no. To indent the XML output you can assign yes to the indent attribute of the output element but the XSLT standard does not define that a processor has to adhere and how the XML output has to be indented. (XSLT: "If the indent attribute has the value yes, then the xml output method may output whitespace in addition to the whitespace in the result tree"). Probably the XML processor of the SQLXML processor does ignore this attribute or maybe you have to tell him explicitly which number of whitespaces he should use for indentation. Personally I never used those classes so I cannot tell what to do. Have a look if there might be a setting for this. Also it could be helpful if you post the code you've got so far, making it easier for us to help you.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
My .NET code is as follows:
public static string ExecuteQueryAndTransform(string connectionString, string queryText, string xslPath)
{
string result = String.Empty;
SqlXmlCommand cmd = new SqlXmlCommand(connectionString);
cmd.XslPath = xslPath;
cmd.RootTag = "Root";
cmd.CommandText = queryText;
using (Stream strm = cmd.ExecuteStream())
{
using (StreamReader sr = new StreamReader(strm))
{
result = sr.ReadToEnd();
}
}
return result;
}
There doesn't appear to be any way to control the indenting from the SQLXML managed classes, so I assume this would be done through the stylesheet.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I found the answer to my problem. If I perform the transform using the .NET framework classes instead of the SQLXML managed classes, I can use the XmlTextWriter to control the indentation.
public static string ExecuteQueryAndTransform(string connectionString, string queryText, string xslPath)
{
string result = String.Empty;
SqlXmlCommand cmd = new SqlXmlCommand(connectionString);
if (!queryText.EndsWith("For XML Auto", StringComparison.CurrentCultureIgnoreCase))
{
queryText += " For XML Auto";
}
cmd.RootTag = "Root";
cmd.CommandText = queryText;
using (Stream strm = cmd.ExecuteStream())
{
XmlTextReader reader = new XmlTextReader(strm);
XPathDocument xd = new XPathDocument(reader, XmlSpace.Preserve);
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(xslPath);
StringWriter stringWriter = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(stringWriter);
writer.Formatting = Formatting.Indented;
writer.Indentation = 3;
writer.IndentChar = ' ';
xslt.Transform(xd, null, writer);
result = stringWriter.ToString();
}
}
Thanks for your help anyway.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I am using xsl:apply-templates and between result of every template i want to insert comma(",") so my code for the same is as below:
<xsl:apply-templates>
<xsl:with-param name="test" >,</xsl:with-param>
</xsl:apply-templates>
but above code is not working,please help me..
Thanks in advance.
Sushant Mathur
Bangalore,
INDIA.
http://n.domaindlx.com/fun2ssh/HOME.htm
|
|
|
|
|
You place text in the select attribute surrounding it with single quotes:
<xsl:apply-templates>
<xsl:with-param name="test" select="','" />
</xsl:apply-templates>
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks for reply George but still its not working
|
|
|
|
|
What are you trying to do?
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Okay, if you are trying to place a comma between each "apply-templates" call, I would put the comma in the template being called:
XML:
<?xml version="1.0" encoding="utf-8" ?>
<colors>
<color>Red</color>
<color>Green</color>
<color>Black</color>
</colors>
XSLT:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Comma Delimited</title>
</head>
<body>
<div>
<xsl:apply-templates select="colors/color"/>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="color">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks a lot Geroge...i was looking for the same kind of solution..
thanks again
|
|
|
|
|
Hi,
I have a problem with with parsing an XML document. In the document I have some character entities like I use XmlDocument.SelectNodes() method to select a specific set of nodes from the XML document, but it happens that some of the tags that are found to have these character entities inside them, and I would like to skip them. My question is that how can that be accomplished. I've tried to use regular expressions to filter out these kind of texts but it didn't work, it read only some empty strings.
Any help is well appreciated!
|
|
|
|
|
You can use internal general entities:
XML:
<!-- WithEntities.xml -->
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE colors [
<!ENTITY red "background-color: red;">
<!ENTITY green "background-color: green;">
<!ENTITY black "background-color: black;">
]>
<colors>
<color style="&red;">Red</color>
<color style="&green;">Green</color>
<color style="&black;">Black</color>
</colors>
C#:
using System;
using System.Xml;
namespace Entity
{
class Program
{
static void Main(string[] args)
{
XmlDocument xml_doc = new XmlDocument();
xml_doc.Load("WithEntities.xml");
XmlNodeList colors = xml_doc.SelectNodes("/colors/color/@style");
foreach (XmlNode color_style in colors)
{
Console.WriteLine(color_style.Value);
}
}
}
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thank you for your reply, but I think that if I do as you mentioned it won't work the way I need to be done. The scenario is as follows. The problem is that I wrote an example for the entitites that I look for but it actually dissapeared from the post message (probably because the reference is invisible). So I have an XML doc and I search for <text> tags in it, but some of these <text> tags contain character entities like & #160; (actually this is single word but I separated with a space just to be visible), and I don't want process such tags that contain this kind of information, I want to skip them. The problem is that when I select the specific nodes and I look for text entries inside them I can't recognize if an entry is a character entity just because it is substituted by the actual value of it (in the previous example I think that entity represents an empty line or whatever). I think now it is clear what I want to achive.
Thanks in advance!
|
|
|
|
|
Hi,
I want to convert MS Excel file to XML file how I can do this in .net 2005 useing C#
Girish Soni
|
|
|
|
|
Have you looked at the Office Interop library?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I am looking to get the following information from my XML:
<attribute>
<ColumnID>TestColumID</ColumnID>
<TableName>Assignment</TableName>
<ColumnName>Delta</ColumnName>
<DataType>System.Double</DataType>
<ColumnUsage>OutputColumn</ColumnUsage>
<ValueType>Single</ValueType>
<DisplayTitle>Adherence Delta</DisplayTitle>
<TypeId>ReportDatabaseColumnAttribute</TypeId>
</attribute>
If I want to print ColumnID (not the value, but the word ColumnID) from my XML tags how do I do that?
-- modified at 18:36 Thursday 25th October, 2007
|
|
|
|
|
How are you parsing the XML?
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
With XSL:
Just a simple for-each attribute and then I try to us a value-of.
|
|
|
|
|
The XPath name() function returns the name of the current element.
Paul Marfleet
|
|
|
|
|
<xsl:for-each select="report/report/attribute">
<tr>
<td>
<xsl:value-of select="name()" />
</td>
<td>
<xsl:value-of select="*"/>
</td>
</tr>
</xsl:for-each>
</xsl:template>
Thats my code and all I get back is 'attribute'
|
|
|
|