|
Thanks for this - I had found the "following-sibling" axis on a tutorial page somewhere which led me to:
<xsl:for-each select="Beds/*/*">
<xsl:choose>
<xsl:when test="not(contains(name(.),'Code')) and .>0">
<Row>
<Description>
<xsl:value-of select="name(..)"/>
<xsl:value-of select="name(.)"/>
</Description>
<Value>
<xsl:value-of select="following-sibling::*[contains(name(),name(.))]"/>
</Value>
<Quantity>
<xsl:value-of select="."/>
</Quantity>
</Row>
</xsl:when>
</xsl:choose>
</xsl:for-each>
Your solution demonstrates to me that I have hardly scratched the surface of XPath, and that there are many ways of achieving the same result!
Is there a performance (or other) benefit to using templates apart from the feeling of doing things properly as opposed to my schonky approach?
Can you recommend any sites or good books to get a deeper insight into XPath/XSLT?
Thanks again for your time,
Al
Edit---
My use of for-each amply demonstrates the adage that when all you have is a hammer...
|
|
|
|
|
Hi Al…thought I'd replied to this, but I guess I killed my browser without pressing Post…doh!
1. apply-templates will very likely have better performance than for-each - there's more scope for the XSLT processor to do optimisations, as apply-templates is a more abstract operation.
2. I've used Michael Kay's XSLT and XPath books, but I think Jeni Tennison's Beginning XSLT would be appropriate for what you want...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
Hey,
I have an Xml schema that I would like upload to my FTP server and have Visual Studio provide intellisense for it. Now, what I've done is that I've created the schema, uploaded to my server (http://www.vestras.net/moonlite/schemas/ximl), and then write the following in the file I'd like intellisense in:
<ximl:Markup xmlns:ximl='http://www.vestras.net/moonlite/schemas/ximl/'>
</ximl:Markup>
However, Visual Studio doesn't provide intellisense. Here's my schema code:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Ximl"
targetNamespace="http://vestras.net/moonlite/schemas/ximl"
elementFormDefault="qualified"
xmlns="http://vestras.net/moonlite/schemas/ximl"
xmlns:mstns="http://vestras.net/moonlite/schemas/ximl"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://vestras.net/moonlite/schemas/ximl http://vestras.net/moonlite/schemas/ximl/ximl.xsd">
<xs:element name="BarItem" id="BarItem">
<xs:annotation>
<xs:documentation>
Defines a bar button.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="guid" type="xs:string" use="required" />
<xs:attribute name="text" type="xs:string" use="required" />
<xs:attribute name="image" type="xs:string" use="optional" />
<xs:attribute name="commandClass" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
<xs:complexType name="Markup">
<xs:sequence>
<xs:element name="Include">
<xs:annotation>
<xs:documentation>
Includes the Ximl file at the given path.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="path" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="String">
<xs:annotation>
<xs:documentation>
Provides a string resource for later use. The resource attribute must contain a unique ID.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="resource" type="xs:string" use="required" />
<xs:attribute name="value" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="Package">
<xs:annotation>
<xs:documentation>
Defines a package that can contain Interface elements. Must have a unique GUID.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="Bar">
<xs:annotation>
<xs:documentation>
Defines a bar. A bar can be a toolbar, a menu or a statusbar.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="BarItem" />
</xs:sequence>
<xs:attribute name="guid" type="xs:string" use="required" />
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Menu" />
<xs:enumeration value="Bar" />
<xs:enumeration value="StatusBar" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="Menu">
<xs:annotation>
<xs:documentation>
Defines a context menu that can be shown on demand.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="BarItem" />
</xs:sequence>
<xs:attribute name="guid" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="guid" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
Any help will be really appreciated.
Thanks,
Theo
|
|
|
|
|
To get Intillisense for Visual Studio the schema file must be placed here
[VS Folder]\Common7\Packages\schemas\xml
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Okay, so I did that and now the schema shows up on the schema list, however when it is included, it doesn't give me any options, it just says "The 'http://vestras.net/moonlite/schemas/ximl:Markup' element is not declared." What does this mean? The Markup element is declared.
|
|
|
|
|
need a little help with this one please.
i have an xml document that contains nodes with cdata sections and am transforming it with xsl. i can get the cdata section to render properly by using <xsl:value-of select="content" disable-output-escaping="yes"/> in my <xsl:template> but if i try to pass the results of that template to another template my cdata section becomes escaped. i tried converting the cdata section to an escaped attribute in my xml but get the same problem.
even an answer of "sorry, not possible." is greatful as i've been trying everything i can think of to get this to work and have come up with nothing.
i can restructure my xml if need be, only i cannot convert the cdata content to valid xml (it needs to be escaped).
sample code:
<xsl:template match="/">
<xsl:variable name="myStructuredContent"><xsl:call-template name="GetStructuredContent"/></xsl:variable>
<xsl:call-template name="Container_RoundedCorners">
<xsl:with-param name="content" select="$myStructuredContent">
</xsl:call-template>
</xsl:template>
<xsl:template name="GetStructuredContent">
<h2><xsl:value-of select="title"/></h2>
<div><xsl:value-of select="content" disable-output-escaping="yes"/></div>
<div><a href="{morelinkhref}"><xsl:value-of select="morelinktext"/></a></div>
</xsl:template>
<xsl:template name="Container_RoundedCorners">
<xsl:param name="content"/>
<div class="RoundedCornerTopLeft"><div class="RoundedCornerTopRight"><xsl:copy-of select="$content"/></div></div>
</xsl:template>
thanks a bazillion in advance.
|
|
|
|
|
Any one with VXML knowledge? I need help
|
|
|
|
|
hi all, How to create xmpp client using C#? I want to develop an application that will chat with xmpp server like jabber etc? 
|
|
|
|
|
choose a single forum to ask your question, and stick to it.
|
|
|
|
|
Hi,
I have uploaded asp.net c# site with MySql database on the web server but i am having the following error
" Could not load file or assembly 'MySql.Data, Version=6.1.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'MySql.Data, Version=6.1.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified."
Please tell me what to do.
Thanks
|
|
|
|
|
how should text should be tagged for bold text in docbook v5 for XML export from Indesign?
Is this correct?
<emphasis role="strong">insert text to be bold here</emphasis>
How would you tag bold vs. italic text in an indesign document you are preparing for XML export?
Make an "emphasis" tag for both italic and bold and add an attribute for bold?
I'd appreciate help sooooooooooooooooo much!
-- Modified Thursday, June 17, 2010 7:49 PM
|
|
|
|
|
<?xml version="1.0" encoding="utf-16"?>
<data>
<student>
<roll>234</roll>
<name>Sidheshwar</name>
<address>
<DoorNo>123</DoorNo>
<Street>MyStreet</Street>
<city>
<code>code01</code>
<name>MyCity10</name>
</city>
<city>
<code>code02</code>
<name>MyCity11</name>
</city>
</address>
<address>
<DoorNo>200</DoorNo>
<Street>MyStreet2</Street>
</address>
<address1>
<Sam>1000address1</Sam>
<Pankaj>MyStreet2000address1</Pankaj>
</address1>
<pin>560004</pin>
</student>
</data>
i have a xml i want to convert xml to csv format using XSLT. I need to write XSL for this xml. It Should be genric.
|
|
|
|
|
|
Hi,
I need help writing to an xml file.
this is the XML file
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<photos>
<photo filename="5.jpg" thumbnail="11.jpg" description="jime" />
<photo filename="6.jpg" thumbnail="121.jpg" description="Water Drops (800x600)" />
<photo filename="8.jpg" thumbnail="22.jpg" description="Fireworks (640x480)" />
</photos>
any ideas how to do that?
Thanks,
Farraj
|
|
|
|
|
Hmmm - bit of information lacking, like where are you getting the information you want to write to the XML file, what language are you using, etc.
And also - can you clarify what help you actually want….I mean, you've got an XML file there, you've obviously written it somehow…so what's your problem?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
thank you for your reply
im using C#. ive tried building such a file using linq
XDocument doc = XDocument.Load(Server.MapPath(@"file.xml"));
var temp = (from element in doc.Root.Elements("photo") where element.Attribute("filename").Value == txtBoxFileName.Text && element.Attribute("thumbnail").Value == txtBoxThumbname.Text && element.Attribute("description").Value == txtBoxDesc.Text select element);
XElement result = null;
if (temp.Count() == 0)
{
result = doc.Root.Elements().Last();
result.AddAfterSelf(new XElement("photo", new XAttribute("filename", txtBoxFileName.Text), new XAttribute("thumbnail", txtBoxThumbname.Text), new XAttribute("description", txtBoxDesc.Text)));
result = doc.Root.Elements().Last();
}
else
{
result = temp.First();
}
result.Add(new XElement("photo", new XAttribute("filename", txtBoxFileName.Text), new XAttribute("thumbnail", txtBoxThumbname.Text), new XAttribute("description", txtBoxDesc.Text)));
doc.Save(Server.MapPath(@"file.xml"));
this.lblxml.Text = "done";
this cool code was made for searching a specific node and add the data inside it.
it helps. it adds! but, not the way i need it. i only need to add one node of ((< photo a="1" b="2" c="3" / >))
which i think its pretty simple, im just not good enough at it
appreciating any help.
thanks,
Farraj
|
|
|
|
|
Don't add the XElement twice :
result.AddAfterSelf( ... )
...
...
result.Add( ... );
Cheers
I don't like my signature at all
|
|
|
|
|
i tried that also but it opens the last node and inserts the node i wanted and closes the last node that was opened.
any idea?
i would love if you write me the suitable code.
thanks a lot
|
|
|
|
|
I have problem in accessing the xml file at run time.one program has to write the file and another has to read the xml file simultaneously.
|
|
|
|
|
Hi guys i have this small class task that im having trouble with. I need to create a PHP file using SAX to generate the display shown below from an XML file. Im not sure how to Use | to represent its level, where the root element orders is at level
zero.
*** what the expected output to look like below. ***
[IMG]http://img13.imageshack.us/img13/6950/75914446.jpg[/IMG]
*** This is the xml source code from which i need to generate the display: ***
<orders>
<order>
<count>37</count>
<price>49.99</price>
<book>
<isbn>0130897930</isbn>
<title>Core Web Programming Second Edition</title>
<authors>
<count>2</count>
<author>Marty Hall</author>
<author>Larry Brown</author>
</authors>
</book>
</order>
<order>
<count>1</count>
<price>9.95</price>
<yacht>
<manufacturer>Luxury Yachts, Inc.</manufacturer>
<model>M-1</model>
<standardFeatures oars=\\\"plastic\\\" lifeVests=\\\"none\\\">false</standardFeatures>
</yacht>
</order>
<order>
<count>3</count>
<price>22.22</price>
<book>
<isbn>B000059Z4H</isbn>
<title>Harry Potter and the Order of the Phoenix</title>
<authors>
<count>1</count>
<author>J.K. Rowling</author>
</authors>
</book>
</order>
|
|
|
|
|
Hello there.
My question is kinda hard to explain, I know. But I'll give it a shot. Hope it works
I have a page(product.aspx) with is formed by an xslt and this xslt gets the values from product.xml.
protected void Page_Load(object sender, EventArgs e)
{
string bebek = Request.QueryString["id"];
XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("product.xml"));
XslCompiledTransform xsltran = new XslCompiledTransform();
xsltran.Load(Server.MapPath("pdetail.xsl"));
xsltran.Transform(xdoc, null, Response.Output);
Not, somehow I managed to link the products with a link like detail.aspx?id={product id, lets say 2}.
Now I created a page named detail.aspx, getting the id of the product and trying the same method to construct the sheet.
Here is my code at pdetail.xsl which need some aid
<xsl:for-each select="root/product/pid="'id'">
i tried
<xsl:for-each select="root/product/pid="{id}">
but i wont work.
I will sort the data with the id which I aim to retrieve by the link. Some of you might say, "dont be a noob, just use asp.net facilities to make it." you might be right but I am not that hard coder here.
phew...hope I made it clear
ps: I use C# for .Net.
|
|
|
|
|
ceviz wrote: "dont be a noob, just use asp.net facilities to make it."
Yes, exactly. Use a repeater, datalist, datagrid, whatever and set the datasource to your xml file.
ceviz wrote: am not that hard coder here.
Then learn. The tools are there to help you work smarter so you don't have to do it the hard way.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
try
/pid[@id]
I dont know the xml docment .
|
|
|
|
|
hi,
I need to do language localization using XML in VC++ (MFC).
I need to do mapping using XML file and i need to scan the XML file for the desired language, so that my output would be in my desired language.
I have no idea, how to go about it.
Please Support
|
|
|
|
|
Suppress Xmlns in InnerXML / Rename an XML node in DOM
The Original:
<?xml version="1.0" encoding="utf-8"?>
<EntrySummaryDeclaration xmlns="http://www.gph.ie/schemas/ics/IE315/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gph.ie/schemas/ics/IE315/v1 C:/GPH/Schemas/IE315/v1/schema.xsd">
<Declaration>
:
:
</Declaration>
</EntrySummaryDeclaration>
The Required new output
<?xml version="1.0" encoding="utf-8"?>
<EntrySummaryDeclarationAmendment xmlns="http://www.gph.ie/schemas/ics/IE313/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gph.ie/schemas/ics/IE313/v1 C:/GPH/Schemas/IE313/v1/schema.xsd">
<Declaration>
:
:
</Declaration>
</ EntrySummaryDeclarationAmendment >
The Actual New Output
<?xml version="1.0" encoding="utf-8"?>
<EntrySummaryDeclarationAmendment xmlns="http://www.gph.ie/schemas/ics/IE313/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://www.gph.ie/schemas/ics/IE313/v1 http://wlhost2:38711/xmlreferencesite/customs/ics/IE313-EntrySummaryDeclarationAmendment/v1/schema.xsd C:/GPH/Schemas/IE313/v1/schema.xsd">
<Declaration xmlns="http://www.gph.ie/schemas/ics/IE313/v1">
</Declaration></EntrySummaryDeclarationAmendment>
The approach
I am using DOM, so I cant rename EntrySummaryDeclaration, therefore I create a new EntrySummaryDeclarationAmendment node, and I assign the inner xml of EntrySummaryDeclaration to the inner xml of EntrySummaryDeclarationAmendment before deleting EntrySummaryDeclaration.
The problem:
The innerXml insists on bringing its original xmlns with it.
The requested solution:
How do I suppress the xmlns in the innerxml – removing it as an attribute after the fact has no effect?
Alternatively – how would I rename EntrySummaryDeclaration as EntrySummaryDeclarationAmendment easly?
The offending Code
XmlNode ^TmpNode;
XmlNode ^IE315_Node;
XmlNode ^IE313_Node;
XmlAttribute ^att;
String^ tmpstr;
if (current_message == MessageType::IE315)
{
if (!namespace_found)
try
{
IE315_Node = doc->SelectSingleNode("//EntrySummaryDeclaration");
}
catch (Exception ^e)
{
MessageString = "Error finding EntrySummaryDeclaration: " + e->Message;
MessageBox::Show(MessageString);
}
else
try
{
IE315_Node = doc->SelectSingleNode("//ie:EntrySummaryDeclaration",nsmgr);
}
catch (Exception ^e)
{
MessageString = "Error finding EntrySummaryDeclaration: " + e->Message;
MessageBox::Show(MessageString);
}
// Create node EntrySummaryDeclarationAmendment
IE313_Node = doc->CreateElement("EntrySummaryDeclarationAmendment");
// Set up the attributes
att = doc->CreateAttribute("xmlns");
att->Value = "http://www.GPH.ie/schemas/ics/IE313/v1";
IE313_Node->Attributes->Append(att);
att = doc->CreateAttribute("xmlns:xsi");
att->Value = "http://www.w3.org/2001/XMLSchema-instance";
IE313_Node->Attributes->Append(att);
tmpstr = "http://www.GPH.ie/schemas/ics/IE313/v1"; // the namespace
DocNamespace = tmpstr;
//Add the new namespace to the document
nsmgr = gcnew XmlNamespaceManager (doc->NameTable);
nsmgr->AddNamespace(L"xsi","http://www.w3.org/2001/XMLSchema-instance");
namespace_found = true;
// if there is no local schema specified, include a default.
tmpstr += " http://wlhost2:38711/xmlreferencesite/stuff/IE313-EntrySummaryDeclarationAmendment/v1/schema.xsd";
SchemaBar->Text = "Schema: http://wlhost2:38711/xmlreferencesite/stuff/IE313-EntrySummaryDeclarationAmendment/v1/schema.xsd";
SchemaName = "http://wlhost2:38711/xmlreferencesite/stuff/IE313-EntrySummaryDeclarationAmendment/v1/schema.xsd";
// Debug schema used for development
MessageString = "NOTE: Using DEBUG Schema!!!";
MessageBox::Show(MessageString);
//C:/GPH/Schemas/IE313/v1/schema.xsd
tmpstr += " C:/GPH/Schemas/IE313/v1/schema.xsd";
SchemaBar->Text = "Schema: C:/GPH/Schemas/IE313/v1/schema.xsd";
SchemaName = "C:/GPH/Schemas/IE313/v1/schema.xsd";
doc->Schemas->Add(DocNamespace,SchemaName);
doc->Schemas->ValidationEventHandler+=eventHandler;
nsmgr->AddNamespace(L"ie", DocNamespace);
schema_found = true;
att = doc->CreateAttribute("xsi:schemaLocation");
att->Value = tmpstr;
IE313_Node->Attributes->Append(att);
// Copy contents of EntrySummaryDeclaration to EntrySummaryDeclarationAmendment
IE313_Node->InnerXml = IE315_Node->InnerXml;
// Delete EntrySummaryDeclaration
Delete_Node(IE315_Node);
/* // Remove any attributes from the Declaration node
if (namespace_found)
try
{
//TmpNode = IE313_Node->FirstChild;//doc->SelectSingleNode("//ie:Declaration",nsmgr);
if (IE313_Node->FirstChild->Name == "Declaration")
{
for (int i = 0; i < IE313_Node->FirstChild->Attributes->Count; i++)
{
MessageString = "Element Node: " + IE313_Node->FirstChild->Name + "; attribute[" + i + "]: Name = "
+ IE313_Node->FirstChild->Attributes[i]->Name
+ "; Value = " + IE313_Node->FirstChild->Attributes[i]->Value;
MessageBox::Show(MessageString);
IE313_Node->FirstChild->Attributes[i]->RemoveAll();
}
IE313_Node->FirstChild->Attributes->RemoveAll();
// doc->Attributes->Remove(IE313_Node->FirstChild->Attributes[0]);
XmlAttributeCollection^ attrs;
attrs = IE313_Node->FirstChild->Attributes;
attrs->RemoveAll();
}
}
catch (Exception ^e)
{
MessageString = "Error finding Declaration: " + e->Message;
MessageBox::Show(MessageString);
}*/
// Add the new EntrySummaryDeclarationAmendment node
doc->AppendChild(IE313_Node);
}
Ger
|
|
|
|