|
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'
|
|
|
|
|
Your context node is attribute; thus, you're printing its name. You want to print out the children elements name. It you just want to print out the first child's name:
<xsl:value-of select="child::*[position()=1]"/>
Given this XML document:
<?xml version='1.0'?>
<report>
<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>
</report>
here is an example of what you are trying to do except it prints out all children names:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table>
<xsl:for-each select="report/attribute">
<tr>
<xsl:for-each select="child::*">
<td><xsl:value-of select="name()"/></td>
<td><xsl:value-of select="."/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi,
i have one requirement. i am applying xslt to my xml file. it is giving one xml file like
<book>
<bookid>101</bookid>
<booktittle>Mathematics</booktittle>
</book>
i am using this one as my datasource and using this source in my crystl reports.
in field expert window i am able to see this element's data(right click on element browse data).
but the problem is if i drag these elements i am getting only element value.
so, what needs to be done for to get other element value in the report.
|
|
|
|
|
i have soml xml files generated in my local msde during net failure, and when net is back i want to get the values from local msde to servers database, i really got stucked in this point, help me out
thanks in advance
Ramkumar S
|
|
|
|
|
Hi..
Can some one please help me how to extract the data values from the following XML file using C++ code.
From the following example, we can observe two types of "CfgType"(Ane Justin and Jessica Sis). Under each "CfgType" there are different "MachineModel" and under that "ModelNo" and followed by "ScreenResolution".
<code>
<?xml version="1.0" encoding="utf-8"?>
<Settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- Configuration Type -->
<CfgType>
<Name>Ane Justin</Name>
<MachineModels>
<MachineModel>
<ModelNo>2345678</ModelNo>
<MonitorTypes>
<MonitorType>
<MonitorName>17" LCD</MonitorName>
<ScreenResolution>
<Resolution>1024*768</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
<ScreenResolution>
<Resolution>800*600</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
</MonitorType>
<MonitorType>
<MonitorName>19" LCD</MonitorName>
<ScreenResolution>
<Resolution>1024*768</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
<ScreenResolution>
<Resolution>800*600</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
</MonitorType>
</MonitorTypes>
</MachineModel>
<MachineModel>
<ModelNo>0789456</ModelNo>
<MonitorTypes>
<MonitorType>
<MonitorName>17" CRT</MonitorName>
<ScreenResolution>
<Resolution>1024*768</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
<ScreenResolution>
<Resolution>800*600</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
</MonitorType>
<MonitorType>
<MonitorName>19" CRT</MonitorName>
<ScreenResolution>
<Resolution>1024*768</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
<ScreenResolution>
<Resolution>800*600</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
</MonitorType>
</MonitorTypes>
</MachineModel>
</MachineModels>
</CfgType>
<CfgType>
<Name>Jessica Sis</Name>
<MachineModels>
<MachineModel>
<ModelNo>456789</ModelNo>
<MonitorTypes>
<MonitorType>
<MonitorName>17" LCD</MonitorName>
<ScreenResolution>
<Resolution>1024*768</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
<ScreenResolution>
<Resolution>800*600</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
</MonitorType>
<MonitorType>
<MonitorName>19" LCD</MonitorName>
<ScreenResolution>
<Resolution>1024*768</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
<ScreenResolution>
<Resolution>800*600</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
</MonitorType>
</MonitorTypes>
</MachineModel>
<MachineModel>
<ModelNo>345678</ModelNo>
<MonitorTypes>
<MonitorType>
<MonitorName>17" CRT</MonitorName>
<ScreenResolution>
<Resolution>1024*768</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
<ScreenResolution>
<Resolution>800*600</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
</MonitorType>
<MonitorType>
<MonitorName>19" CRT</MonitorName>
<ScreenResolution>
<Resolution>1024*768</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
<ScreenResolution>
<Resolution>800*600</Resolution>
<RefreshRate>60</RefreshRate>
</ScreenResolution>
</MonitorType>
</MonitorTypes>
</MachineModel>
</MachineModels>
</CfgType>
</Settings>
</code>
Now, the output should be shown as follows on the console window:
Ane Justin
2345678
17" LCD
1024*768
60
800*600
60
19" LCD
1024*768
60
800*600
60
0789456
17" LCD
1024*768
60
800*600
60
19" LCD
1024*768
60
800*600
60
Jessica Sis
456789
17" LCD
1024*768
60
800*600
60
19" LCD
1024*768
60
800*600
60
345678
17" LCD
1024*768
60
800*600
60
19" LCD
1024*768
60
800*600
60
Could some one please help me in showing the output as shown above...
Many Thanks...
-- modified at 8:02 Wednesday 24th October, 2007
|
|
|
|
|
Certainly nobody will write the whole code for you. Try it yourself and if you get stuck on some specific point come back here and we'll be glad to help you. If you use .NET take a look at the System.Xml namespace. Otherwise MSXML may be interesting to 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
|
|
|
|
|
I suggest starting by studying MSXML. In the MSDN library (msdn.microsoft.com), it's under "Win32 and COM Developement/Data Access and Storage/MSXML" This documents some software that you can download for free from MSDN downloads.
Nathan
|
|
|
|
|
Why does this query return only one group node from the given XML? I know it's not the worlds best XML, but this is a very young prototype.
XmlNodeList groupsNodes = sectionXml.SelectNodes("Groups/Group");
<?xml version="1.0" encoding="utf-8" ?>
<Section name="ClientInvoices">
<Groups>
<Group name="Headers" driverQuery="ClientInvoices" destination="XCINVK.TXT">
<Line recordDefinition="InvHeader" />
</Group>
<Group name="Detail" driverQuery="ClientInvoices" groupKey="InvNoSort" destination="XCINVK.TXT">
<Line recordDefinition="DetailFooter" />
<Footer>
<Line recordDefinition="InvDetail" />
</Footer>
</Group>
</Groups>
</Section>
[Added 17:38]
Sorry, it was a brain fart on my part. I quickly switched to another document to compare operation, and forgot to switch back. I was querying a document with only one group. Last modified: 29mins after originally posted --
|
|
|
|
|
The following code should return an XmlNodeList object that contains 2 nodes:
XmlDocument sectionXml = new XmlDocument();
sectionXml.Load("sample.xml");
XmlNodeList groupsNodes = sectionXml.SelectNodes("/Section/Groups/Group");
Changing the XPath query produced the required output.
Paul Marfleet
|
|
|
|
|
See my mod to the message. Thanks anyway.
|
|
|
|