I have an xml file in this format
<xml>
<entity>&acces;</entity>
</xml>
I am trying to retrieve the value of entity using <xsl:value-of select="xml/entity"> but it's returning empty string. Any hint how to achieve this?
Is that what your XML looks like?
It is missing the entity declaration or DTD reference that would define that entity. Your XML parser should throw an error, but may just be silently "skipping" it, so when you attempt to obtain the value, it is empty.
Related
I'm using wso2 data-mapper to map input schema with output schema. problem here is we are unable to map with xml attributes(either it can be in input schema or output schema)
We are able to map with element based xml but unable to map with attribute values
Below link will show you the input schema and output schema
https://drive.google.com/file/d/1Dmupfl71Ww_mLQB0gRL1RnmaebrUnzwh/view?usp=sharing
I tried mapping xml elements to attributes on both Windows and Mac and both seem to work fine. I would advise to start with a small version of your xml tree and expand to see what the problem could be. One difference that stands out: I put sample data in my XML which does not seem to be the case in your example (since it says 'NULL' everywhere).
XML input:
<test>
<owner>theowner</owner>
<status>working</status>
</test>
XML output:
<test>
<Users owner="me" status="working" />
</test>
I have a xslt transformation from xml to pdf using apache fop. Whether is possible to add codnition to xslt transormation? I want to not display column in result pdf if all values in column equals zero. It's possible?
Yes, it is possible. In fact, you can do declarative/functional programming logic with XSLT using templates, functions and conditionals. Since you did not provide any example code, I will suppose that you have a table element in your xslt, and you want to show it only if there is some non-zero value to be displayed.
In this case, you should use an recursive template to walk along the list in your xml, and keep checking with XPath if the values are equal to zero. If you find zero, call this same template for the next value, if not, call the template that builds the table for you.
Notice that to use condition, you can use xsl:for-each, xsl:when or xsl:if elements to make the decision given the XPath expression. The xsl:template is used for iterating recursively with parameters, given that instance variables do not exist in xsl.
Using XSLT how do we render CDATA tag?
In xslt I dont want to create CDATA tag using text or declaring in xml
output tag using cdata-section-elements,
it should read it dynamically from input, if element value is around CDATA than
then xslt should render the same, as shown below
Input:
<A><![CDATA[Hello World]]></A>
XSLT Output :
<A><![CDATA[Hello World]]></A>
The data model XSLT/XPath/XQuery operate on does not know any CDATA sections so you can't simply preserve them as the tree you operate on simply contains a text node in both cases (i.e. for <foo>a & b</foo> and <foo><![CDATA[a & b]]></foo> the tree is a foo element containing a single text child node with the string value a & b).
So there is no way in pure XSLT to achieve what you want, unless you pre-process the input to convert CDATA sections into some structure like elements the XSLT data model allows you to detect and distinguish. Andrew Welch has http://andrewjwelch.com/lexev/ to do that in a Java environment.
Thus if you use an XSLT 2.0 processor like Saxon 9 with Java you could use that approach.
With XSLT, I am processing an xml file which might not have any nodes, other than the root. I want to output a special message on the html page for this case. I am using a for-each element to process the xml file. How do I check if the xml file has any actual nodes in it?
How Do I Check if an XML File Has No
Nodes?
By definition, any well-formed XML document contains at least a top element.
Therefore, any XML document contains some nodes -- there can't be an XML document that has no nodes.
I understand this question as asking: "How to determine that the top element of an XML document has no descendents?"
This is in fact an XPath question. This XPath expression:
/*[not(node())]
is true() exactly when the top element of the document has no child nodes (elements, text-nodes, processing instructions or comments).
The top element can still have attributes and it always has namespace nodes, but these two kinds of nodes are not considered to be exactly "children".
/*[not(node()) and not(#*)]
is true() exactly when the top element has no child nodes and no attributes.
/*[not(*)]
is true() exactly when the top element has no child element nodes (but it still can have text-node children, processing-instruction children and comment-nodes children).
I have an xml string
<grandparent>
<parent>
<child>dave</child>
<child>laurie</child>
<child>gabrielle</child>
</parent>
</grandparrent>
What I want to get is the data raw xml that's inside the parent.
I'm using MSXML
iXMLElm->get_xml(&bStr);
is returning
<parent>
<child>dave</child>
<child>laurie</child>
<child>gabrielle</child>
</parent>
.
iXMLElm->get_text(&bStr);
returns
davelauriegabrielle
What function do I use if I want to get?
<child>dave</child>
<child>laurie</child>
<child>gabrielle</child>
Is anyone aware of some good documentation on these functions? Everything I've seen is a linked nightmare.
Iterate over the child nodes and build the string manually.
If you are using MSXML, this should be a case of getting the child node of the grandparent node.
So, if iXMLElm is the grandparent and it has only one child node, you can just use...
iXMLElm->get_firstChild(&iXMLChildElm)
...and then...
iXMLChildElm->get_xml(&bStr)
...to get the three child elements.
If there are multiple items under grandparent you could use selectSingleNode instead to use XPath for selecting the node with the inner XML you want.
The MSDN documentation is quite reasonable on the interfaces and calls available.
If you are using IXMLDOMElement, then
HRESULT getAttribute(
BSTR name,
VARIANT *value);
is the method in which 'name' is attribute name and 'value' is output parameter which will contain value of the attribute in string format.