|
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.
|
|
|
|
|
Announcing the release of Liquid XML Studio 2008
a Freeware XML Development Environment.
Download available from www.liquid-technologies.com.
Key features include
- An Advanced Graphical Schema Editor
- XML Editor, with auto-complete, syntax highlighting & validation
- Web Service Browser, supports calling Soap services
- XPath Expression Builder, visualise XPath expressions
- Documentation Generator, HTML Docs from your XML schemas
- Code Generation, C++, C#, .Net, Java, VB .Net & VB6 (trial)
Liquid XML...XML the smart way!
|
|
|
|
|
Please don't post product advertisements like this in the forums, even for free products. If you want to advertise your product, do it the right way and purchase advertising space on the site.
|
|
|
|
|
This is probably a "Doh!" moment...
I had stored some values in an XML file thus:
<?xml ... ?>
<Commands>
<Command ID="test">
<Field>f1</Field>
<Field>f2</Field>
<Field>f3</Field>
<Field>f4</Field>
</Command>
<Command ID="test2">
<Field>f1</Field>
<Field>f2</Field>
<Field>f3</Field>
<Field>f4</Field>
</Command>
</Commands>
I wanted to deserialize these into into a class so I could enumerate each command, and then the string array of fields. Long story short is I got lost in the Xml.Serialization namespace attributes, and gave up.
The root was easy, an [XmlRoot("Commands")] public class Commands which contained a Command array.
However I could not figure out how to get the Command array to return an array of Field[] strings.
Anything like public string Field[] would result in <Field><string>value</string></Field>
In the end I gave up and rewrote the XML by adding an intermediate class Fields
which I could prefix with [XmlArray("Fields"), XmlArrayItem("Field")]..
<?xml ... ?>
<Commands>
<Command ID="test">
<Fields>
<Field>f1</Field>
<Field>f2</Field>
<Field>f3</Field>
<Field>f4</Field>
<Fields>
</Command>
<Command ID="test2">
<Fields>
<Field>f1</Field>
<Field>f2</Field>
<Field>f3</Field>
<Field>f4</Field>
</Fields>
</Command>
</Commands>
But is there a way to achieve the original result??
'Howard
|
|
|
|
|
There is no direct way to achieve the original:
<?xml ... ?>
<Commands>
<Command ID="test">
<Field>f1</Field>
<Field>f2</Field>
<Field>f3</Field>
<Field>f4</Field>
</Command>
<Command ID="test2">
<Field>f1</Field>
<Field>f2</Field>
<Field>f3</Field>
<Field>f4</Field>
</Command>
</Commands>
since each <Field/> would be considered a stand-alone class field with the same name (which would be a syntax error). However, you can use XSLT to translate the deserialized format into the original format.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks - I sort of figured out that I must be doing it wrong as there did not seem to be a way to achieve it. So I wasn't missing something after all.
'Howard
|
|
|
|
|
hi,
well I've made an XSL file and I linked it to the XML file with this code
<?xml version="1.0" encoding="utf-8"?>
<?xml:stylesheet type="text/xsl" href="e2.xsl"?>
When I open the xml file in IE the result is fine. but when I open it in FireFox 2.0.0.7 it give me this error:
XML Parsing Error: not well-formed
Location: file:///d:/xsl/e_changed.xml
Line Number 2, Column 6:<?xml:stylesheet type="text/xsl" href="e2.xsl"?>
-----^
Where am I going wrong??
Thanks in advance
Rocky
You can't climb up a ladder with your hands in your pockets.
|
|
|
|
|
You got your style sheet processing instruction wrong. It should be:
<?xml-stylesheet type="text/xsl" href="e2.xsl"?>
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
<pre><?xml version="1.0" encoding="utf-8"?>
<b><?xml:stylesheet type="text/xsl" href="e2.xsl"?>
</pre>
<?xml-stylesheet type="text/xsl" href="e2.xsl"?></b>
These two are the same... the above line is for declaring that the document is an XML document. You're not saying I should remove the above line r u?
Rocky
You can't climb up a ladder with your hands in your pockets.
|
|
|
|
|
This is wrong:
<?xml version="1.0" encoding="utf-8"?>
<?xml:stylesheet type="text/xsl" href="e2.xsl"?>
and this is right:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="e2.xsl"?>
Geo
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
ok so the : was wrong !!
Thanks George.
Rocky
You can't climb up a ladder with your hands in your pockets.
|
|
|
|
|
hi i m ajay
can any one of u tell me that for javascript problem where i should write my problem...
actually i want to make a fuction that can compare two dates....the date are in mm/dd/yyyy formate..
i want a alert that comes in that condition when second date will less thn first...
and i want this onclick of button
thxxx
Ajay Rathi
software engineer
NOIDA(UP),INDIA
|
|
|
|
|
Arihant rathi wrote: can any one of u tell me that for javascript problem where i should write my problem...
Certainly not in the XML/XSL or the SQL / ADO / ADO.NET forum. Personally, I would try the Web development forum.
"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
|
|
|
|
|
System.Exception: The XSLT path is invalid. It refers to an external resource, uses invalid syntax, or the XSLT was not found in the catalog
Exception: The XSLT path is invalid. It refers to an external resource, uses invalid syntax, or the XSLT was not found in the catalog.]
[Exception: Cannot load XSLT specified at ‘DataTransform1.xsl’.]
[Exception: An error occurred during rendering of the report.]
[Exception: An unexpected error occurred in Report Processing.]
Microsoft.Reporting.WebForms.ServerReport.ServerUrlRequest(Boolean isAbortable, String url, Stream outputStream, String& mimeType, String& fileNameExtension) +489
Microsoft.Reporting.WebForms.ServerReport.InternalRender(Boolean isAbortable, String format, String deviceInfo, NameValueCollection urlAccessParameters, Stream reportStream, String& mimeType, String& fileNameExtension) +924
Microsoft.Reporting.WebForms.ServerReportControlSource.RenderReport(String format, String deviceInfo, NameValueCollection additionalParams, String& mimeType, String& fileExtension) +84
Microsoft.Reporting.WebForms.ExportOperation.PerformOperation(NameValueCollection urlQuery, HttpResponse response) +153
Microsoft.Reporting.WebForms.HttpHandler.ProcessRequest(HttpContext context) +75
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +303
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
|
|
|
|
|
I am using the transform below to convert an ADO persisted XML to ExcelXML. The conversion is done correctly except the following minor issue.
The output from <xslt:template match="z:row"> block generates
this --> <Row ss:Height="15" xmlns="">
instead of --> <Row ss:Height="15">
Where is this xmlns="" coming from?
My Transform.
<?xml version="1.0" encoding="UTF-8"?>
<!--
This stylesheet is used to transform ADO recordset to Excel XML. By default, the
sheet converts the recordset to a complete Excel XML workbook
-->
<!-- xsl:param name="MakeHeader"/-->
<xslt:stylesheet xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
xmlns:rs="urn:schemas-microsoft-com:rowset"
xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:z="#RowsetSchema"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns ="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
version="1.0"
exclude-result-prefixes="rs s dt z o x ss">
<xslt:output method="xml" omit-xml-declaration="no" indent="yes" encoding="UTF-8"/>
<xslt:template match="/">
<!-- Full -->
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns ="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="AltItem">
<Alignment ss:Vertical="Top" ss:WrapText="1"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#C0C0C0"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#C0C0C0"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#C0C0C0"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#C0C0C0"/>
</Borders>
<Font ss:Color="#4A3C8C" ss:Size="10"/>
<Interior/>
</Style>
<Style ss:ID="Header">
<Alignment ss:Horizontal="Center" ss:Vertical="Top" ss:WrapText="1"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#C0C0C0"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#C0C0C0"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#C0C0C0"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#C0C0C0"/>
</Borders>
<Font ss:Size="10" ss:Color="#F7F7F7" ss:Bold="1"/>
<Interior ss:Color="#4A3C8C" ss:Pattern="Solid"/>
</Style>
<Style ss:ID="Item">
<Alignment ss:Vertical="Top" ss:WrapText="1"/>
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#C0C0C0"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#C0C0C0"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#C0C0C0"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#C0C0C0"/>
</Borders>
<Font ss:Color="#4A3C8C" ss:Size="10"/>
<Interior ss:Color="#CCCCFF" ss:Pattern="Solid"/>
</Style>
</Styles>
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author>Exported from TopTraders Web Application</Author>
<Created>2003-04-22T13:43:53Z</Created>
<Version>1.0</Version>
</DocumentProperties>
<!-- Full -->
<!-- Output worksheet -->
<Worksheet ss:Name="Sheet">
<Table>
<!-- output the column name in the first row -->
<Row ss:Height="15">
<xslt:for-each select="/xml/s:Schema/s:ElementType[@name='row']/s:AttributeType">
<xslt:sort select="@name" />
<Cell ss:StyleID="Header">
<Data ss:Type="String">
<xslt:value-of select="@name" />
</Data>
</Cell>
</xslt:for-each>
</Row>
<!-- Output the record contents -->
<xslt:apply-templates select="/xml/rs:data/z:row">
<!-- <xslt:sort select="@CustomerID" /> -->
</xslt:apply-templates>
</Table>
</Worksheet>
<!-- Full -->
</Workbook>
</xslt:template>
<!-- Template to match individual record -->
<xslt:template match="z:row">
<Row ss:Height="15">
<xslt:variable name="current_row" select="." />
<xslt:for-each select="/xml/s:Schema/s:ElementType[@name='row']/s:AttributeType">
<xslt:sort select="@name" />
<xslt:variable name="attrName" select="@name" />
<Cell ss:StyleID="Item">
<Data ss:Type="String">
<xslt:choose>
<xslt:when test="s:datatype/@dt:type='dateTime'">
<xslt:value-of select="ms:format-date($current_row/@*[name()=$attrName],'MM/dd/yyyy')" />
</xslt:when>
<xslt:otherwise>
<xslt:value-of select="$current_row/@*[name()=$attrName]" />
</xslt:otherwise>
</xslt:choose>
</Data>
</Cell>
</xslt:for-each>
</Row>
</xslt:template>
</xslt:stylesheet>
|
|
|
|
|
In the style sheet the Row element is child of the stylesheet element (root) and a template element that both declare no default namespace. Since the Row element has no prefix specifying a namespace it is put into the empty namespace (xmlns=""). When put into the target XML file the mapping to the namespace persists. I guess you expected it to be copied to the target XML file and then belonging to the default namespace declared on the Workbook element.
"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
|
|
|
|
|
Thanks stefan for the comments, I was under the assumption that the subsequent template inherits the namespaces but I guess I was wrong.
Regards.
|
|
|
|