Empty nodes vs no nodes
Questions about XML that are not covered by the other forums should go here.
			- 
				Brian_donovan
 - Posts: 3
 - Joined: Tue Sep 17, 2019 10:27 pm
 
Empty nodes vs no nodes
Post by Brian_donovan »
Hi, pleas help! I am creating a XSLT 1.0 formato to export data from an XML doc. I have an example of my problem below:
I am extracting all the data using only wildcards like name(), /* or . so I do not know the name of any node this is just an example.
My problem is that when getting the values the node <title> returns nothing I need to get an error text or something worning me that there is a node with nothing. My test code lookes like this but it cant see the empty tag pleas help
			
			
									
									
						Code: Select all
 
 <cd name="Bonny" size="">
    <title></title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
    <company>CBS Records</company>
    <price>19.90</price>
    <year>1928</year>
  </cd>
  My problem is that when getting the values the node <title> returns nothing I need to get an error text or something worning me that there is a node with nothing. My test code lookes like this but it cant see the empty tag pleas help
Code: Select all
<xsl:for-each select="*//@*">
<xsl:choose>
 <xsl:when test=".='' "><text style="color:red;"> Error </text></xsl:when>
   <xsl:otherwise>
         <xsl:value-of select="."/>
 </xsl:otherwise>
</xsl:choose>
</xsl:for-each>
'- 
				adrian
 - Posts: 2894
 - Joined: Tue May 17, 2005 4:01 pm
 
Re: Empty nodes vs no nodes
Hi,
There is no empty text node. The node just doesn't exist.
Also, <xsl:for-each select="*//@*"> iterates only on attributes, everything else (elements and text) is ignored.
If you want to iterate on elements, maybe use <xsl:for-each select="//*"> Although I should mention there are better ways to do this in XSLT, by using xsl:templates.
Then test if there is no text() node:
REgards,
Adrian
			
			
									
									There is no empty text node. The node just doesn't exist.
Also, <xsl:for-each select="*//@*"> iterates only on attributes, everything else (elements and text) is ignored.
If you want to iterate on elements, maybe use <xsl:for-each select="//*"> Although I should mention there are better ways to do this in XSLT, by using xsl:templates.
Then test if there is no text() node:
Code: Select all
<xsl:when test="not(text())"><text style="color:red;"> Error in <xsl:value-of select="name(.)"/></text></xsl:whenAdrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
						<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Return to “General XML Questions”
			
				Jump to
				
			
		
			
			
	
	- Oxygen XML Editor/Author/Developer
 - ↳ Feature Request
 - ↳ Common Problems
 - ↳ DITA (Editing and Publishing DITA Content)
 - ↳ Artificial Intelligence (AI Positron Assistant add-on)
 - ↳ SDK-API, Frameworks - Document Types
 - ↳ DocBook
 - ↳ TEI
 - ↳ XHTML
 - ↳ Other Issues
 - Oxygen XML Web Author
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen Content Fusion
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen JSON Editor
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen PDF Chemistry
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen Feedback
 - ↳ Feature Request
 - ↳ Common Problems
 - Oxygen XML WebHelp
 - ↳ Feature Request
 - ↳ Common Problems
 - XML
 - ↳ General XML Questions
 - ↳ XSLT and FOP
 - ↳ XML Schemas
 - ↳ XQuery
 - NVDL
 - ↳ General NVDL Issues
 - ↳ oNVDL Related Issues
 - XML Services Market
 - ↳ Offer a Service