the xml has this format:
UDF Fields
Inline Portion - Child of multiple Nodes
<Activity>
<UDF>
<TypeObjectId>458</TypeObjectId>
<TextValue>MILS-Z.M1.01</TextValue>
</UDF>
Definition Portion - Child of top node
<UDFType>
<DataType>0</DataType>
<IsSecureCode>0</IsSecureCode>
<ObjectId>458</ObjectId>
<SubjectArea>0</SubjectArea>
<Title>Contract Package</Title>
</UDFType>
I need to find the parents of the UDF by going in through UDFType, looping a search for UDF and then listing the parents of the UDF. Any advice?
Use the xpath: //UDF/.. to match the parent nodes of all UDF elements. Or you could just do //*[UDF], which specifically matches any element that has a UDF child.
Related
I am new to xslt.
I want to get the parent node of matched child node(ends with)
Sample XML:
can have elements before and after parent tag
Here the result should be "parent"
Query: find first parent element name of the child element ends with smile ("endwithsmile")
I could able to get the element which contains ("endswithsmile"), but not ends with .
ends-with is not working.
<xsl:value-of select="(//*[contains(local-name(), 'Identifier')])"/>
I also tried using "../" to get parent but didnt work.
Sample xml for above question :::
<parent>
<childendwithsmile>
<test></test>
</childendwithsmile>
</parent>
<parent1>
<childendwithsmile>
<test></test>
</childendwithsmile>
</parent1>
Try this XPath:
//*[substring(name(), string-length(name()) - string-length('smile') + 1) = 'smile']/..
#Kiril's answer should work, but I prefer this approach that selects a parent based on its child, rather than selecting the child and going back up the tree:
//*[*[substring(name(), string-length(name()) - string-length('smile') + 1) = 'smile']]
I have some trouble with a special XML-document.
The XML has only 3 nodes like the below the example:
<solidName>
<unknownNodeName>
<everytimeTheSame>blablabla</everytimeTheSame>
<everytimeTheSame2>blablabla</everytimeTheSame2>
<unknownChildNodeName>
<everytimeTheSame>blablabla</everytimeTheSame>
<everytimeTheSame2>blablabla</everytimeTheSame2>
</unknownChildNodeName>
</unknownNodeName>
</solidName>
I need to select the unknownNodeName and the unknownChildNodeName to use the function
<xsl:value-of select="everytimeTheSame"/> and so on. I tried to use a for-each select function, but I found no way to get the unknow Name of the node.
Are there any possibilities for my problem? Is it possible to say <xsl:for-each select ="NodeNumberX"> or things like that <xsl:for-each select ="/*/*">
to use the function and so on
is not a good description of what you want to do.
Selecting "unknown nodes" (i.e. nodes whose name you do not know, but you do know their position in the document's tree) is trivial by using the * symbol in an XPath expression, possibly combined with a positional predicate.
For example:
/*/*/*[2]
will select the <everytimeTheSame2> element in your example.
XSLT: Ignore and skip data for an element and its entire branch of child elements if an attribute is set false?
I have an XML document which has Document > Sections > Sub Sections > Items > Sub Items > Super Subs etc and so on.
Now one common 'Boolean' Attribute or Attribute Set I am setting as common for all Elements at every level is "V" for visibility or visible i.e. Allowing me to hide/ skip or make invisible entire section of the document.
Since it is Boolean it can hold 1 or 0 i.e. True/ False.
I'd like to be able to IGNORE and SKIP processing and output of any element and its entire branch of child elements if I need it hidden/ unprocessed and ignored by simply changing one Boolean attribute as a flag.
What would be a good, clean, efficient way of going about this?
Would there be a common Xpath expression that would allow this to apply globally to entire set of elements at all levels across the XML document?
I welcome all suggestions and alternative ways of implementing and going about this.
e.g. XML:
<Document>
<Section v="1">Data
<SubSection v="1">SS1..</SubSection>
<SubSection v="0">SS2..</SubSection>
</Section>
<Section v="0"></Section>
<Section v="1"></Section>
</Document>
If you are processing your document with a normal <xsl:appy-templates/> recursive walk over the input tree then you just need
<xsl:template match="*[#V='0']" priority="10"/>
which says to output nothing and don't process the children of elements with V="0"
I want to remove all spaces with normalize space() while counting all nodes and use a Filter on those.
What I want is something like this:
<{namespace}:Text>
<{namespace}:Info>This is text from Info Node</{namespace}:Info>
Here is text which i want to find
</{namespace}:Text>
I want to count all children from {namespace}:Text , but i want to ignore {namespace}:Info and [namespace}:otherelement and the content of those should be ignored too.
I want as a result from count a 1 so that I know there are nodes which I have to process, so I can call templates workwithcontent or workwithempty.
But of course I do want to find other nodes too which don't fit the filter.
It sounds like you want something like
<xsl:template match="{namespace}:Text">
<xsl:variable name="count"
select="count(child::node()[not(self::{namespace}:Info)])" />
...
This will count all child nodes of <{namespace}:Text>, including both text and element nodes, except for <{namespace}:Info> elements.
If that's not what you need, please clarify.
The child:: axis is optional, but makes it more obvious what the XPath expression will select.
Using MSXML4, I am creating and saving an xml file:
MSXML2::IXMLDOMDocument2Ptr m_pXmlDoc;
//add some elements with data
SaveToDisk(static_cast<std::string>(m_pXmlDoc->xml));
I now need to acquire a substring from m_pXmlDoc->xml and save it. For example, if the full xml is:
<data>
<child1>
<A>data</A>
<One>data</One>
<B>data</B>
</child1>
</data>
I want to store this substring instead:
<A>data</A>
<One>data</One>
<B>data</B>
How do I get this substring using MXML4?
Use XPath queries. See the MSDN documentaion for querying nodes. Basically you need to call the selectNodes API with the appropriate XPath expression that matches the part of the DOM you are interested in.
// Query a node-set.
MSXML4::IXMLDOMNodeListPtr pnl = pXMLDom->selectNodes(L"//child/*");