XSL if else condition

We can achieve if else by using below code <xsl:choose> <xsl:when test=”something to test”> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> So here is what I did <h3>System</h3> <xsl:choose> <xsl:when test=”autoIncludeSystem/autoincludesystem_info/@mdate”> <!– if attribute exists–> <p> <dd><table border=”1″> <tbody> <tr> <th>File Name</th> <th>File Size</th> <th>Date</th> <th>Time</th> <th>AM/PM</th> </tr> <xsl:for-each select=”autoIncludeSystem/autoincludesystem_info”> <tr> <td valign=”top” ><xsl:value-of select=”@filename”/></td> <td valign=”top” ><xsl:value-of … Read more

XPath : select all following siblings until another sibling

You could do it this way: ../node[not(text()) and preceding-sibling::node[@id][1][@id=’1′]] where ‘1’ is the id of the current node (generate the expression dynamically). The expression says: from the current context go to the parent select those child nodes that have no text and from all “preceding sibling nodes that have an id” the first one must … Read more

Python – ElementTree- cannot use absolute path on element

Turns out I needed to say target.findall(“.//StepText”). I guess anything without the ‘.’ is considered an absolute path? Updated working code: def search(): root = ET.parse(INPUT_FILE_PATH) for target in root.findall(“//Script”): stepTexts = target.findall(“.//StepText”) for stepText in stepTexts: if FIND.lower() in stepText.text.lower(): print target.attrib[‘name’],’ — ‘,stepText.text

XPath using starts-with function

Use: /*/ITEM[starts-with(REVENUE_YEAR,’2552′)]/REGION Note: Unless your host language can’t handle element instance as result, do not use text nodes specially in mixed content data model. Do not start expressions with // operator when the schema is well known.

XPath query for XML node with colon in node name

You need to learn about namespaces and how to define/register a namespace in your XPath engine so that you can then use the associated prefix for names in that registered namespace. There are plenty of questions in the xpath tag asking how to use names that are in a namespace — with good answers. Search … Read more

Parse XML Simple String using Java XPath

You can’t reuse the same InputSource for multiple evaluate() invocations because it’s automatically closed. Hence you’re getting the Stream closed IO exception. Try this InputSource source1 = new InputSource(new StringReader(xml)); InputSource source2 = new InputSource(new StringReader(xml)); String msg = xpath.evaluate(“/resp/msg”, source1); String status = xpath.evaluate(“/resp/status”, source2); System.out.println(“msg=” + msg + “;” + “status=” + status); … Read more

How to insert a new element under another with xmlstarlet?

I had a similar problem: I had a Tomcat configuration file (server.xml), and had to insert a <Resource> tag with pre-defined attributes into the <GlobalNamingResources> section. Here is how it looked before: <GlobalNamingResources> <!– Editable user database that can also be used by UserDatabaseRealm to authenticate users –> <Resource name=”UserDatabase” auth=”Container” type=”org.apache.catalina.UserDatabase” description=”User database that … Read more

Can XPath match on parts of an element’s name?

This answer is for XPath 1.0 where there is no equivalent of the XPath 2.0 standard ends-with() function. The following XPath 1.0 expression selects all elements in the xml document, whose names end with the string “fu”: //*[substring(name(),string-length(name())-1) = ‘fu’] Note that -1 is the offset from the end of name() (the length of “fu” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)