|
I'd like to pass a parameter into an XSLT to search for a specific element within an XML document. My document has this form:
<library>
<folder id="1">
<file />
<file />
</folder>
<folder id="2">
<file />
<folder id="3" />
<folder id="4">
<file />
<file />
</folder>
</folder>
</library>
I want to be able to pass in a parameter into my XSLT and search for a particular folder - let's say id="4".
This is how I've been approaching it:
<xsl:stylesheet ...>
<xsl:param name="folderID" />
<xsl:template match="/library//folder[@id=$folderID]">
<!-- more code here -->
</xsl:template>
</xsl:stylesheet>
But I get this error: System.Xml.Xsl.XsltException: '/library//folder[@id=$folderID]' is an invalid XPath expression. ---> System.Xml.XPath.XPathException: /library//folder[@id=$folderID] is an invalid key pattern. It either has a variable reference or key function.
What might be a better or more correct way to approach this?
Michael Hodnick
|
|
|
|
|
Hi Michael. At first glance, I think the syntax
<xsl:template match="/library//folder[@id=$folderID]"> is wrong. You have two slashes between library and folder - did you want instead something like this?
<xsl:template match="//folder[@id=$folderID]"> to match a folder node regardless of where it is in the heirarchy?
|
|
|
|
|
I've also tried what you are suggesting, but still receive the following error: '//folder[@id=$folderID]' is an invalid XPath expression. ---> System.Xml.XPath.XPathException: //folder[@id=$folderID] is an invalid key pattern. It either has a variable reference or key function.
Michael Hodnick
www.kindohm.com
blogs.kindohm.com
|
|
|
|
|
I've just tried your approach in xsltproc (part of libxslt) and it works fine. I presume you are passing a value for folderID into the transform engine???
I used the command 'xsltproc --param folderID 4 a.xsl a.xml' to perform the transform (the xsl and xml names are obvious )
This was the XSL I used (based on yours - the template selector is the same as yours)
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="xsl">
<xsl:output method="xml" encoding="ISO8859-1" indent="yes" omit-xml-declaration="no"/>
<xsl:param name="folderID"/>
<xsl:template match="/library//folder[@id=$folderID]">
<Wib>
<xsl:value-of select="count(./file)"/>
</Wib>
</xsl:template>
</xsl:stylesheet>
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
My previous reply was wrong - you can't use a variable reference in a template selector - see this
You'll have to use something like the following instead (i.e. put the predicate on a higher-level select expression and keep the template matching rule wide):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="xsl">
<xsl:output method="xml" encoding="ISO8859-1" indent="yes" omit-xml-declaration="no"/>
<xsl:param name="folderID"/>
<xsl:template match="/">
<xsl:apply-templates select="/library//folder[@id=$folderID]"/>
</xsl:template>
<xsl:template match="/library//folder">
<Wib>
<xsl:value-of select="count(./file)"/>
</Wib>
</xsl:template>
</xsl:stylesheet>
HTH
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
|
I've been developing an IDL-like programming language and wrote a system of complex namespaces that cover most of core features (everything from garbage collecting to automatic serialization, dynamic casting ...). I'd like to ask how many of you feel this is a good thing to do and how many that it's a bad thing?
Software developer
MA, USA
|
|
|
|
|
Creating the language is not the problem. Support and popularity is. If no one uses the language, or close to no one, or there are better or more popular languages out there already -> what is the point of having a new language?
If your language does basically the same thing C# or VB.NET does will it actually help the community?
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
Hi,
I have an XML file, which contains several nodes like the ones below:
<saml:Attribute AttributeName="ssbAssertionVersion" AttributeNamespace="http://www.syntegra.com">
<saml:AttributeValue xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion">1.0</saml:AttributeValue>
</saml:Attribute>
- <saml:Attribute AttributeName="cn" AttributeNamespace="http://www.syntegra.com">
<saml:AttributeValue xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion">Doe Joanna B</saml:AttributeValue>
</saml:Attribute>
----> My objective is to , take the value present inside the tag, "saml:AttributeValue " and populate it in my custom grid control, which will accept the element name as a parameter and display its value.
Problems:
1. ELEMENT NAME IS THE SAME IN ALL THE NODES, "saml:AttributeValue".
2.I dont want to reframe a new xml file out of this present one, since it increases the processing time.
3.I cant give an xpath query, directly to the my custom grid control.it will accept only the element name of a xml file.
Please help me, if you can think of a logic, that has to finally make the 'saml:AttributeValue' element name unique,without reforming a new xml so that i can directly feed that into my grid control.
Thanks In advance,
Regs, Manivannan
|
|
|
|
|
Hello
I am having problem with the for loop
here is the varialbe declaration
<xsl:variable name="client1ID" select="//clients/client/clientId" />
This shows 12345
<xsl:value-of select="$client1ID"/>
1. This works
<xsl:for-each select="//clients/client[clientId='12345']">
<xsl:value-of select="./ssn"/>
</xsl:for-each>
2. This doesn't work, it returns all ssn of all the clients
<xsl:for-each select="//clients/client[clientId=$client1ID]">
<xsl:value-of select="./ssn"/>
</xsl:for-each>
I want to know what's wrong and I want point 2 to work, using for loop, any idea.
thanks
gundappa
|
|
|
|
|
Hi there. Your variable is selecting a nodeset, not a single string value. In your first <xsl:value-of select="$client1ID" /> , you're displaying the value of the first node in the set.
In your first for-each statement, the predicate [clientId='12345'] is returning a single node, and the resulting value-of select="./ssn" XPath syntax correctly displays the value of its child ssn node.
In your second for-each statement, because the variable $client1ID is a nodeset, not a string or numeric type, it is being evaluated to the boolean value true within the predicate. The expression [clientId=$client1ID] is then evaluated as [clientId=true] ; because clientId exists as a node, the complete predicate is evaluated to true and all nodes are returned.
I think you may want to define your original variable such that it evaluates to a real string value and not a nodeset. Just a thought.
|
|
|
|
|
Thanks a lot for your response. I am new to XSL, can you please suggest how to define original variable such that it evaluates to a real string value and not a nodeset.
TIA
gund
|
|
|
|
|
Hey Mike
Thanks a lot for your suggestion, I was able to reolve it by changing the variable declaration
<xsl:variable name="client1ID"><xsl:calue-of select="//clients/client/clientId" /></xsl:variable>
and it worked!
Regards
gund
|
|
|
|
|
Hi all,
I have a bunch of XML files, which all together can be considered as a database.
I need to be able to save only one node at a time in an XML file. (such as on tuple at a time in a RDBMS).
I already use DOM in my C++ code to process XML files.
The problem is that the Save() in DOM saves all the the elements of the file.
Which is not what I want.
I have searcher and not found an easy way to do that but I need a generic solution that is data-content independant because I need to do that on different XML files.
I am not very familiar with SAX.
The only thing I can find for the moment:
- Have the xml descrition of the element before I do the Save of my element. ->(string xmlNode1)
- Extract the XML from IXMLDOMElement with the "xml" property of the element
I want to save (string xmlNode2).
- Do a text search and replace of the string xmlNode1 with the string xmlNode2.
Which is very ugly and goes against XML usage.
Unless I write my own parsing in SAX which is very troublesome since I have many different xml files.
I would be very surprised to be the first to have this problem.
Please help.
Thanks,
Julien.
Julien Mazloum
|
|
|
|
|
create a new xml object instane, and a the node you want to save
from that instance with the ->appendChild() method.You should be able to do it.
|
|
|
|
|
Thanks but it is not really what I want because, to create a new xml object instance I would need to reload the file.
I want to have a way to do an update of a node WITHOUT reloading the whole XML file.
Thanks,
Julien.
|
|
|
|
|
I have to make a Software which collects schedule information from any source on the web and to save this in a common format by using XML.
can some one please give me some tips on what the heck might be a "common format!!" and where is the best place to learn about this "Collection and saving thing" on the web...please help as I need this for my course work...
thanks....
J.
|
|
|
|
|
|
I am not sure, but could "common format" mean that you have to use your own format, but keep it same for every web source? I don't know exactly what you mean, so I will not write here how to parse HTML page or so, cuz it maybe isn't what you mean...
As soon as you make more clear what you want to do, I can tell u more.
Sorry for this beeing very "helpful", but as soon as you will explain what exactly you want to do, i'll be more exact, too.
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
The aim of this project is firstly to collect schedule information for TV or Radio or both (Radio listing is explicitly required by the client) from any source on the web; so it’s very important for this software to be flexible and sophisticated enough for it to be able to go and search for the required listings, and to select them from the midst of other unwanted information, then to save this in a common format (i.e. a format which works on most platforms) ; By using XML(Extensible Mark up Language).
Extra features that can be added which are not required by the client but can be a bonus and more pleasing for him can be to search for specific topics or presentation in a user defined format (whatever suites the client); and this may be implemented by using some sort of algorithm which can defines the subject and then match it against web resources (listing).
|
|
|
|
|
hi,
huh this is quite difficult task, I think. I can only give u some of my ideas. It is hard to collect information form any source, since they may vary in format. Most of schedule information for TV&radio will be probably stored in a table. Unfortunately, most of web is written very bad. Very probably there will by some "syntax errors" like unclosed <tr>, unquoted attributes, etc. So it is not good idea try to read it as XML. My strategy would be use of RegEx (is ur project in .NET, isn't it?). Then you can check table (or tables) wheater they contain some keywords (like time information) to make sure you are collecting information from schedule and not from navigation menu I would not implement searching myself, rather use some Google hacks ( get relevant links from google search hidden from user). I am very interested in automated collecting information from web, NLP, artificial intelligence, etc. Unfortunately I am very beginner in these fields... With known format of schedule information, ideas above should be enough. For any source (=> unknown format) it's much more complicated. Anyway, I am interested in ur project and I would be pleased to know more about it...
best regards,
David
(hopefully I hepled a litte)
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Dear CPians,
I get an XML documents using the GetXML method of the DataSet object. I use an XSLT file which is stored on the file system to transform the XML. During the transformation though, I need to inject some data from another XML fle which is on the file system.
I know that I have to use the XmlResolver object to resolve external sources. Is there an example of how I include the external data and how will I instruct the XmlResolver object to process the data?
Thank you.
theJazzyBrain
Excellence is not an act, but a habit! Aristotle
|
|
|
|
|
Hi
I am using XML serializationn in C#. I have code like this.
public class Doc
{
[XmlArrayItem (ElementName="TNArray",
Type=typeof(ReTN[]))]
public object[] Obj;
}
[XmlRoot("TNA")]
public class ReTN
{something...}
Here I am trying to set XML node as "TNA" instead of class name "ReTN". [XmlRoot("TNA")] works when I serialize single object, that means when I say [XmlElement(Type=typeof(ReTN))]. In single object case I am getting node name as "TNA". If I serialize array of objects as I was doing above it gives class name("ReTN") as node name. Any thoughts.
Any help is greatly appreciated.
Thanks
Raj
|
|
|
|
|
Hello,
I am trying the following code with MS-SOAP Toolkit v3.0:
Dim oConnector As New HttpConnector30
Dim oSerializer As New SoapSerializer30
Dim oReader As New SoapReader30
oConnector.Property("EndPointURL") = "https://172.16.1.95/Service1.asmx"
oConnector.Property("WinHTTPAuthScheme") = 8
oConnector.Property("UseSSL") = True
oConnector.Property("SSLClientCertificateName") = "CURRENT_USER\MY\Nirav"
oConnector.Connect
oConnector.Property("SoapAction") = "https://172.16.1.95/HelloWorld"
oConnector.BeginMessage
... ' serializing the SOAP message here
oConnector.EndMessage ' Gives the ERROR here!
But even though the same works perfectly with "http://", it is giving the following error with "https://" -
-------------------------------------------------------
Runtime error '5400'
Connector: SSL certificate common name (host name field) is incorrect HRESULT=0x800A1529 - Connector: Unspecified HTTP error. HRESULT=0x800A1518 -------------------------------------------------------
Since the same service works fine if I invoke it from my IE6, I suppose the certificate should be fine. But this is something mysterious, and no material about this error...
Am I doing something wrong? Please suggest me a solution for this...
Thanks a lot!
Rgds,
Nirav
* Artificial intelligence is no match for natural stupidity! *
|
|
|
|
|
You resolve the problem? I am with the same problem
|
|
|
|