Answer the question
In order to leave comments, you need to log in
How to make it so that empty nodes in xml are not displayed?
After converting to a certain pattern, nodes with empty entries sometimes appear. They need to not show up.
Probably somehow through the text() check. Something does not work.
Has anyone encountered such a problem?
Answer the question
In order to leave comments, you need to log in
If nodes are selected by XPath, you can only apply the pattern to nodes with text
/path/to/node[text()]
/path/to/node[string(.)]
select
or for-each
, then you can, respectively, specify in the pattern:<xsl:template match="node[text()]"> ... </xsl:template>
apply-templates
, and then it turns out that nothing came out and the element is empty as a result, then you can first apply-templates
inside the variable, and then check if anything worked out:<xsl:variable name="contents"> <xsl:apply-templates /> </xsl:variable> <xsl:if test="string($contents)"> <MyElement> <xsl:copy-of select="$contents" /> </MyElement> </xsl:variable>
Depends on your tree structure and template.
In general, here, read - soa-howto.blogspot.com/2009/09/how-to-remove-empty-nodes-from-xml.html
You can create a "delete template" for any tag that has no content. It will look something like this:
<xsl:template match="*[not text() and not self::*]"></xsl:template>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question