|
Please don't cross post; enter your question in one forum only.
The best things in life are not things.
|
|
|
|
|
I am receiving an XML file with data like below;
<meterref>00895289</meterref>
<readingdate>14/12/10</readingdate>
<reading>2</reading>
<readingdate>28/09/10</readingdate>
<reading>0</reading>
<readingdate>23/08/10</readingdate>
<reading>0</reading>
<readingdate>02/03/10</readingdate>
<reading>9</reading>
<meterref>00895298</meterref>
<readingdate>02/12/10</readingdate>
<reading>275</reading>
<readingdate>22/09/10</readingdate>
<reading>274</reading>
<readingdate>02/06/10</readingdate>
<reading>274</reading>
<readingdate>02/03/10</readingdate>
<reading>274</reading>
<meterref>00895995</meterref>
<readingdate>02/12/10</readingdate>
<reading>425</reading>
<readingdate>22/09/10</readingdate>
<reading>420</reading>
<readingdate>02/06/10</readingdate>
<reading>411</reading>
<readingdate>02/03/10</readingdate>
<reading>404</reading>
<meterref>00896005</meterref>
<readingdate>02/12/10</readingdate>
<reading>185</reading>
<readingdate>22/09/10</readingdate>
<reading>182</reading>
<readingdate>02/06/10</readingdate>
<reading>178</reading>
<readingdate>02/03/10</readingdate>
<reading>174</reading>
Now obviously I can read down from the top and see which readings go with which meter. I think that xsl cannot easily do that.
So my question is, can I work with this data without too much messing about, or should I just go to the provider of the xml and tell them to do it properly?
Thanks in advance for any help or advice.
Every man can tell how many goats or sheep he possesses, but not how many friends.
|
|
|
|
|
Although the example you gave does not exploit XML to its fullest potential, it's a welcome departure from entirely unmarked text files with pipes used as separators.
I've seen XML that encodes list indexes in tag names, like this:
<item3>78</item3>
<item1>34</item1>
<item0>12</item0>
<item2>56</item2>
So I don't think your situation is quite as bad
I think that your answer greatly depends on what you are planning to do with this data, and how hard it would be for the provider to change their code to generate a more XML-like XML for you. If your provider is a utility company in the United States, you will almost certainly be better off just working with the flawed format. Otherwise, you risk spending countless hours convincing them to change the format for you, and then ending up working with that flawed format anyway 
|
|
|
|
|
I need to present the data in a single field in a meaningful way for a user;
Meter Ref: 00895289
Reading Taken 14/12/10, Reading 2
Reading Taken 28/09/10, Reading 0
Meter Ref: 00895995
Reading Taken
And so on.
The provider is actually a company that my company owns, although the work is being done for another company that we own. I can make them do anything, it is just at some point there will be an argument about cross charging that goes away if I do the work instead.
Every man can tell how many goats or sheep he possesses, but not how many friends.
|
|
|
|
|
I would definitely ask them to make reading items meters' children, rather than siblings. While they are at it, I'd ask them to put dates and values into attributes too. Depending on the technology that they use, it could be as simple as ten-line change on their end.
Doing the work on your end invites maintenance headache, with a potential of costing your company a lot more. Especially if someone inherits this project from you, and needs to implement enhancements.
|
|
|
|
|
dasblinkenlight wrote: I'd ask them to put dates and values into attributes too
I don't think that is a good idea.
|
|
|
|
|
Why? The most complete treatment of the attribute-vs-element question[^] that I was able to find mentions the principle of structured information, saying that "If the information is expressed as an atomic token, use attributes." I've been intuitively following that rule for many years, because it is easy to remember, it results in consistent schemas, lends itself nicely to use in automated schema generators, and makes resulting documents more compact. That's why I think that using attributes in this case is desirable.
|
|
|
|
|
From that same document and from the single principle (of the several) that you are referring to.
"Attributes are designed for expressing simple properties of the information represented in an element."
As an example a font is a property of the text of a book. So the font is an attribute. The text is not. Notice as well that the text itself is a element value.
So exactly how would you structure the data of the OP such that an element value has attributes which are properties?
Besides the principles (plural) of that link which I also use I can only note that in my experience attributes also suffer from a lack of easy display and no way to comment values (xml comments.)
|
|
|
|
|
Notice as well that the text itself is a element value.
A text that does not represent a value of an enumeration should always be in an element, because of the mandatory attribute normalization in XML.
So exactly how would you structure the data of the OP such that an element value has attributes which are properties?
Like this:
Personally, I would prefer the markup below as more consistent, but the one above is perfectly OK.
<pre lang="xml">
<meter ref="00895289">
<reading date="14/12/10" value="2"/>
<reading date="28/09/10" value="0"/>
<reading date="23/08/10" value="0"/>
<reading date="02/03/10" value="9"/>
</meter>
<meter ref="00895298">
<reading date="02/12/10" value="275"/>
<reading date="22/09/10" value="274"/>
<reading date="02/06/10" value="274"/>
<reading date="02/03/10" value="274"/>
</meter>
in my experience attributes also suffer from a lack of easy display and no way to comment values (xml comments.)
I tend to disregard display concerns, as XML is not specifically a presentation-oriented language. As far as inability to comment attributes goes, I think that humans should not be exposed to reading and writing XML so much as to need comments. There was an excellent post on the subject[^] ten years ago, which I think is even more applicable today.
|
|
|
|
|
Second example is inconsistent with the link since the attributes do not act on anything.
First is just odd.
dasblinkenlight wrote: I tend to disregard display concerns...
The link you posted specifically lists readability as a principle.
|
|
|
|
|
Reformating as blocks rather than sequential would seem a bit more friendly.
|
|
|
|
|
I have an xhtml file that is valid and im running a simple xslt sheey against him only to be able to catch the body element and it dosent work.
The xml:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<a name="top"></a>
</body>
</html>
The xslt:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="node()"/>
</xsl:template>
<xsl:template match="body">
here
</xsl:template>
</xsl:stylesheet>
|
|
|
|
|
Change your xml as shown below.
<html xmlns="http://www.w3.org/1999/xhtml"> --- > <html>
This name space reference is creating issues.
Thanks,
Nagaraj
|
|
|
|
|
I have a string in an XML file and I want to display each letter (or number) in a different box (div ). So I made the div tag and I want to display one letter (or number) in it.
Currently I have this code:
...
<!-- text to itterate over -->
<xsl:variable name="text">name person</xsl:variable>
<xsl:call-template name="loop">
<xsl:with-param name="text" />
</xsl:call-template>
...
<xsl:template name="loop">
<xsl:param name="text" />
<xsl:param name="count">1</xsl:param>
<xsl:if test="not(count = string-length($text))">
<div class="fillIn">
<xsl:value-of select="substring($text, $count, 1)"/>
</div>
<xsl:call-template name="loop">
<xsl:with-param name="count" select="$count + 1" />
<xsl:with-param name="text" select="$text" />
</xsl:call-template>
</xsl:if>
</xsl:template>
Any advice on what I can improve? Because this isn't working.
Thanks in advance!
|
|
|
|
|
1. Use $test as a constant.
2. Rename your param $text to something else, e.g. $sub_text and select="$text" (without this you have an empty string
3. Your if test is incorrect. count does not have a '$' in front of it.
"not($count = string-length($text))"
4. The last parm $text should be renamed to $sub_text and select attrib set to "substring($text, $count + 1)" since you should be chopping off the first character and passing it to the next recursion.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Tuesday, June 7, 2011 7:55 PM
|
|
|
|
|
Hello mates,
I am new to XSL and would like to transform a NewML G2 format XML into another XML.
For example I have:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
- Structure: NML2 SNI Text
-->
<!-- ========================================================= -->
<newsMessage xmlns="http://iptc.org/std/nar/2006-10-01/" xmlns:rtr="http://www.reuters.com/ns/2003/08/content" xmlns:x="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<header>
<transmitId>tag:123.com,0000:newsml_N19279043:609406403</transmitId>
<priority>3</priority>
<destination>ABX</destination>
</header>
<itemSet>
<newsItem conformance="power" guid="tag:reuters.com,0000:newsml_N19279043" standard="NewsML-G2" standardversion="2.1" version="609406403" xml:lang="en">
<itemMeta>
<itemClass qcode="icls:text" rtr:msgType="S"/>
<provider literal="reuters.com"/>
<versionCreated>2011-05-20T05:00:27.000Z</versionCreated>
</itemMeta>
<contentMeta>
<urgency>3</urgency>
<infoSource literal="Reuters" role="cRole:origProv"/>
<subject qcode="N2:BNK"/>
<headline>My Headline</headline>
<by>ABC</by>
</contentMeta>
<contentSet>
<inlineXML contenttype="application/xhtml+html" wordcount="881">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title/>
</head>
<body>
<p>Paragraph A</p>
<p>* Paragraph A</p>
</body>
</html>
</inlineXML>
</contentSet>
</newsItem>
</itemSet>
</newsMessage>
I would like my result XML to be something like:
<?xml version="1.0" encoding="UTF-8"?>
<MyData>
<MyTransmitId>tag:123.com,0000:newsml_N19279043:609406403</MyTransmitId>
<MyHeadline>My Headline</MyHeadline>
<MyContent>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title/>
</head>
<body>
<p>Paragraph A</p>
<p>* Paragraph A</p>
</body>
</html>
</MyContent>
</MyData>
I come out with the following XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" indent="yes" encoding="utf-8" />
<xsl:template match="/newsMessage">
<MyTransmitId>
<xsl:value-of select="header/transmitId"/>
</MyTransmitId>
<MyHeadline>
<xsl:value-of select="itemSet/newsItem/contentMeta/headline"/>
</MyHeadline>
<MyContent>
<xsl:value-of select="itemSet/newsItem/contentSet/inlineXML"/>
</MyContent>
</xsl:template>
</xsl:stylesheet>
However it transforms to something not quite right.
What is wrong with my XSL?
Thank you very much.
|
|
|
|
|
Hi,
I would use the following stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" media-type="text/html"/>
<xsl:template match="/">
<xsl:element name="MyData">
<xsl:element name="MyTransmitId">
<xsl:value-of select="//*[name()='transmitId']"/>
</xsl:element>
<xsl:element name="MyHeadline">
<xsl:value-of select="//*[name()='headline']"/>
</xsl:element>
<xsl:element name="MyContent">
<xsl:copy-of select="//*[name()='inlineXML']/*"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
I am not sure this is the best way, but it seems to generate the desired output
Erik
|
|
|
|
|
Thanks a lot Erik! This is exactly what I want.
I happened to get another solution, I posted here for the benefits of others:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:itpc="http://iptc.org/std/nar/2006-10-01/">
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<xsl:template match="/itpc:newsMessage">
<MyData>
<MyTransmitId>
<xsl:value-of
select="itpc:header/itpc:transmitId"/>
</MyTransmitId>
<MyHeadline>
<xsl:value-of
select="itpc:itemSet/itpc:newsItem/itpc:contentMeta/itpc:headline"/>
</MyHeadline>
<MyContent>
<xsl:copy-of
select="itpc:itemSet/itpc:newsItem/itpc:contentSet/itpc:inlineXML/*"/>
</MyContent>
</MyData>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
|
I would like to write queries over an XML data set using the XQuery language virsion 1.0 or 2.0
and generate single XML output file for the following xml files :
authors.xml
<br />
<authors><br />
<author><br />
<name>AMADEO, Giovanni Antonio</name><br />
<born-died>b. ca. 1447, Pavia, d. 1522, Milano</born-died><br />
<nationality>Italian</nationality><br />
<biography> Giovanni Antonio Amadeo was an Italian early Renaissance sculptor, architect, and engineer..</biography><br />
</author><br />
</authors><br />
---------------------------------
artworks.xml
<br />
<artworks><br />
<artwork><br />
<title> Fade of the church </title><br />
<author> AMADEO, Giovanni Antonio </author><br />
<date>1473</date><br />
<technique> Marble <technique><br />
<location> Certosa, Pavia </location><br />
<form> architecture </form><br />
<type>religious</type><br />
</artwork><br />
</artworks><br />
----------------------------------
Sample for the expected output :
output.xml
<br />
<authors><br />
<author><br />
<name>AMADEO, Giovanni Antonio</name><br />
<born-died>b. ca. 1447, Pavia, d. 1522, Milano</born-died><br />
<nationality>Italian</nationality><br />
<biography>Giovanni Antonio Amadeo was an Italian early Renaissance sculptor, architect, and engineer..</biography><br />
<artworks form="architecture"><br />
<artwork date="1473"><br />
<title>Fade of the church</title><br />
<technique>Marble</technique><br />
<location>Certosa, Pavia</location><br />
</artwork><br />
</artworks><br />
</authors><br />
I would like to merge these two XML documents and create a new XML file, in which the following information should be stored for each author: name, born-died, nationality,biography, and all artworks. The artworks are grouped by form and then sorted on date. For each artwork, title, technique, and location are stored.
thank you .
Edit/Delete Message
|
|
|
|
|
And what exactly is your question?
|
|
|
|
|
I have two xml files "authors.xml" and "artworks.xml"
I want to write queries over the XML data set in a file "combine.xq" using the XQuery language virsion 1.0 or 2.0
and generate single XML output file "output.xml" .
Thanks
|
|
|
|
|
Neno99 wrote: I want to write queries over the XML data set
So, once again, what is your problem or question?
The best things in life are not things.
|
|
|
|
|
You already told us what you want to do.
That is not a question.
If you want someone to write the entire solution for you then you should ask that. Someone might do it. Or not.
|
|
|
|
|
Hi can anyone tell me, how to bind a data to class objects from a list, so that i can pass it in xml request..
here is my code in xsd generated class.
public partial class SetValue
{
private string dANameField;
private string dAIDField;
private SetValueType setValueTypeField;
public string DAName
{
get
{
return this.dANameField;
}
set
{
this.dANameField = value;
}
}
public string DAID
{
get
{
return this.dAIDField;
}
set
{
this.dAIDField = value;
}
}
public SetValueType SetValueType
{
get
{
return this.setValueTypeField;
}
set
{
this.setValueTypeField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://xml.abc.com/ns/msjava/lrm")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://xml.abc.com/ns/msjava/lrm", IsNullable = false)]
public partial class SetValueType
{
private string valueTypeIDField;
private string valueTypeField;
private string valueField;
private Function functionField;
private Field fieldField;
public string ValueTypeID
{
get
{
return this.valueTypeIDField;
}
set
{
this.valueTypeIDField = value;
}
}
public string ValueType
{
get
{
return this.valueTypeField;
}
set
{
this.valueTypeField = value;
}
}
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
public Function Function
{
get
{
return this.functionField;
}
set
{
this.functionField = value;
}
}
public Field Field
{
get
{
return this.fieldField;
}
set
{
this.fieldField = value;
}
}
}
here i have to do something, so that i can add the data in this list to class type(SetValueType), so that later i will convert it into xml format..
SetValue DAESetvalue = new SetValue
{
DAID=oSetValue.DAID,
DAName=oSetValue.DAName
};
DADirective.SetValue = DAESetvalue;
List<SetValueType> SetValueTypeList = new List<SetValueType>();
GetValueTypeCondition(gValueTypeCondition,SetValueTypeList);
public void GetValueTypeCondition(Grid gValueTypeCondition,List<SetValueType> SetValueTypeList)
{
int rowcount = 0;
if (gValueTypeCondition.RowDefinitions != null)
rowcount = gValueTypeCondition.RowDefinitions.Count;
for (int i = 0; i < rowcount; i++)
{
SetValueType oSetValueType = new SetValueType();
foreach (UIElement element in gValueTypeCondition.Children.Cast<UIElement>().Where(element => Grid.GetRow(element) == i))
{
if (element is ComboBox)
{
ComboBox cbvaluetype = (ComboBox)element;
if (cbvaluetype.Uid != null)
{
Object obj = ((ComboBoxItem)(cbvaluetype.SelectedItem)).Tag;
if (obj != null)
{
if (cbvaluetype.Uid == DataKey.FUNCTION_KEY)
{
DAFunction dafunction = (DAFunction)obj;
oSetValueType.ValueTypeID = "2";
oSetValueType.ValueType = "Function";
oSetValueType.Function.FunctionID = dafunction.FunctionID;
oSetValueType.Function.FunctionName = dafunction.FunctionName;
oSetValueType.Function.DataType1 = dafunction.DataType1;
oSetValueType.Function.DataType2 = dafunction.DataType2;
oSetValueType.Function.DataType3 = dafunction.DataType3;
}
else if (cbvaluetype.Uid == DataKey.COLUMN_CONDITION_KEY)
{
DAColumn dacobj = (DAColumn)obj;
oSetValueType.ValueTypeID = "3";
oSetValueType.ValueType = "Field";
oSetValueType.Field.FieldID = dacobj.id;
oSetValueType.Field.FieldValue = dacobj.name;
}
}
}
}
else if (element is TextBox)
{
TextBox txtValueType = (TextBox)element;
switch (txtValueType.Uid)
{
case DataKey.TEXT_VALUE_KEY:
oSetValueType.ValueTypeID = "1";
oSetValueType.ValueType = "Value";
oSetValueType.Value = txtValueType.Text.Replace("_", "").Trim();
break;
case DataKey.TEXT_FUNCTION_VALUE_KEY:
oSetValueType.Function.FunctionValue = txtValueType.Text.Replace("_", "").Trim();
break;
}
}
}
SetValueTypeList.Add(oSetValueType);
}
}
so any help like how to do it...
|
|
|
|
|
If I understand the question.
You have a XSD which represent a type X.
You want to to create XML that has a list of X values.
That of course is invalid in terms of the XSD. By definition the XSD does not define a list so it cannot include a list.
So your choice are change the XSD, use a different XSD or don't use a list (as a single XML production.)
|
|
|
|