|
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.)
|
|
|
|
|
Dear all,
In my application i have an XML like this..
I want to perform a search in this XML Based on SubID, ModuleId, TaskName, between start and end dates. Please help me. Also i need all the parents of the searched nodes without siblings.
<Tasks>
<Task TaskId=1 PId=0 SubId=0 ModuleId=0 TaskName="Task 1" StartDate="1 Apr 2011" EndDate="12 Apr 2011">
<Task TaskId=2 PId=1 SubId=0 ModuleId=0 TaskName="Task 2" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
<Task TaskId=3 PId=1 SubId=0 ModuleId=0 TaskName="Task 3" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
<Task TaskId=4 PId=1 SubId=0 ModuleId=0 TaskName="Task 4" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
<Task TaskId=5 PId=1 SubId=1 ModuleId=0 TaskName="Task 5" StartDate="1 Apr 2011" EndDate="12 Apr 2011">
<Task TaskId=6 PId=5 SubId=0 ModuleId=0 TaskName="Task 6" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
<Task TaskId=7 PId=5 SubId=0 ModuleId=0 TaskName="Task 7" StartDate="1 Apr 2011" EndDate="12 Apr 2011">
<Task TaskId=8 PId=7 SubId=0 ModuleId=0 TaskName="Task 8" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
</Task>
<Task TaskId=9 PId=5 SubId=0 ModuleId=0 TaskName="Task 9" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
</Task>
<Task TaskId=10 PId=1 SubId=0 ModuleId=0 TaskName="Task 10" StartDate="1 Apr 2011" EndDate="12 Apr 2011"/>
</Task>
</Tasks>
Please help
Regards,
DJ
|
|
|
|
|
I am not answering your entire question, but I have a thought about one component of it:
Do you have any control over the date format of the initial XML that is provided to you?
If you were to receive the date values in ISO format (YYYY-MM-DD), then you could use a simple string comparison (greater than or less than) in your xpath or xsl to determine whether the dates fall in date ranges.
--Greg
|
|
|
|
|
OK, I posted another XPath query a few days ago and you might think that by now I should have figured this stuff out a little better, but...
I need to retrieve the ts_value from the following XML snippet where the ts_date is a specific value. The document is:
<timeSeries>
<ts><ts_date>2010-06-30</ts_date><ts_value>1.235648</value></ts>
<ts><ts_date>2010-07-31</ts_date><ts_value>564654.235648</value></ts>
<ts><ts_date>2010-08-31</ts_date><ts_value>5465465.235648</value></ts>
<ts><ts_date>2010-09-30</ts_date><ts_value>952031.235648</value></ts>
</timeSeries>
I'm trying to follow the xpath syntax I've seen on the web as much as possible.
/timeSeries/ts[ts_date='2010-09-30']
But I'm getting no results.
Anyone?
|
|
|
|
|
Got it!
Here is the XPath to retrieve the ts_value for the particular ts_date node :
String xPath = "/timeSeries/ts[ts_date='2010-06-30']/ts_value";
Your xpath will return the whole node "ts" node. To get to the "ts_value" node, you have to add this : /ts_value.
and then retrieve its value :
XmlNode node = xmlDoc.SelectSingleNode(xPath);
String nodeValue = node.InnerText;
Hope it helped!
People with high attitude deserve the standing ovation of our highest finger!
My Blog![ ^]
|
|
|
|
|
Nice one!! I think I was trying to be too iterative; the parser was returning null because I wasn't selecting the ts_value to return.
Cheers!
|
|
|
|
|
Heeeeelp please,
I have problems to build my own xsd file.
I need to create tags xsd for these tags xml:
<Condition>
<Value Vtype=“Color”>
<!-- Tags_1 -->
<List Value=“RE|GB=Red;FR=Rouge"/>
<List Value=“BL|GB=Blue;FR=Bleu"/>
<List Value=“BK|GB=Black;FR=Noir"/>
</Value>
<Value Vtype=“Form”>
<!-- Tags_2 -->
<List Value=“RE|GB=Rectangel;FR=Rectangle"/>
<List Value=“CI|GB=Circle;FR=Cercle"/>
</Value>
</Condition>
what i want is to link Tags 1 to value of attribute type of elemt Value.
example: if i have in XML
<Value Vtype=“Color”>
it should be followed by Tags_1 not Tags_2 and reverse.
|
|
|
|
|
I would like to know how to do that too - although I have a sneaky feeling it can't be done
|
|
|
|
|
I wrote a small .Net app that validates an XML with an XSD.
It looks like it is working, until I did the following below.
the XML is validated although the attribute is restricted to 8 chars.
What could I be doing wrong?
many thanks.
[Solved]
like this:
public static void Validate(string xml_file, string xsd_file, string xmlnamespace){
schemaexception = null;
validationexception = null;
XmlReader reader = null;
XmlReaderSettings xmlreadersettings = new XmlReaderSettings();
XmlSchemaSet myschema = new XmlSchemaSet();
try{
xmlreadersettings.Schemas.Add(xmlnamespace, xsd_file);
xmlreadersettings.ValidationType = ValidationType.Schema;
xmlreadersettings.ValidationEventHandler += new ValidationEventHandler(xmlreadersettings_ValidationEventHandler);
reader = XmlReader.Create(xml_file, xmlreadersettings);
while(reader.Read());
}
catch (XmlException XmlExp){
schemaexception = XmlExp;
}
catch(XmlSchemaException XmlSchExp){
schemaexception = XmlSchExp;
}
catch(Exception GenExp){
schemaexception = GenExp;
}
finally{
reader.Close();
}
}
[/Solved]
[EDIT]I found an online tool dat also validates the xml against the xsd and that seems to work. it even says what the exact error is. I'll have to have a look at the .Net code. If anyone has a good article about it, let me know. (I'll also, of course, search for myself)[/EDIT]
xml
<MyCode value="abcdefSSSgh"/>
xsd
<xs:element name="MyCode" minOccurs="1">
<xs:complexType>
<xs:attribute name="value" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
.Net code
public static Exception Validate(string xml_file, string xsd_file, string xmlnamespace){
Exception xmlexception = null;
XmlReader reader = null;
XmlSchemaSet myschema = new XmlSchemaSet();
try{
reader = XmlReader.Create(xml_file);
myschema.Add(xmlnamespace, xsd_file);
reader.Settings.Schemas.Add(myschema);
while (reader.Read());
}
catch (XmlException XmlExp){
xmlexception = XmlExp;
}
catch(XmlSchemaException XmlSchExp){
xmlexception = XmlSchExp;
}
catch(Exception GenExp){
xmlexception = GenExp;
}
finally{
reader.Close();
}
return xmlexception;
V.
modified on Friday, March 25, 2011 6:07 AM
|
|
|
|
|
I have just downloaded the Codegenerator add in to LiquidStudio.
I'm underwhelmed. It doesnt appear to give me anything more than I get when I run the scheme through the Visual Studio add in XSD.EXE
Am I missing something?
Ger
|
|
|
|