I'm new to XSLT. I have the following XML I'm trying to extract strings from. But I have to make sure there are no empty strings since the receiving application doesn't allow for empty fields. So in the case where the source XML has no value in the description field that carries the role attribute "descRole:audio" and is next to the sibling node 'itemClass' that has the role attribute of qcode="icls:video", I want to insert a whitespace character.


XML:



<?xml version="1.0" encoding="UTF-8"?>
<newsMessage xmlns="http://ift.tt/1oQ4tRO">
<itemSet>
<packageItem>
<itemMeta/>
<contentMeta/>
</packageItem>
<newsItem>
<itemMeta>
<itemClass qcode="icls:text"/>
</itemMeta>
<contentMeta>
<description role="descRole:intro" xml:lang="en"></description>
<description role="descRole:moreInfo" xml:lang="en"></description>
</contentMeta>
</newsItem>
<newsItem>
<itemMeta>
<itemClass qcode="icls:video"/>
</itemMeta>
<contentMeta>
<description role="descRole:audio" xml:lang="en">NATURAL</description>
</contentMeta>
</newsItem>
</itemSet>
</newsMessage>


XSL:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://ift.tt/tCZ8VR" xmlns:d="http://ift.tt/1oQ4tRO" version="1.0">
<xsl:template match="/">
<xsl:value-of select="/d:newsMessage[1]/d:itemSet[1]/d:newsItem[d:itemMeta/d:itemClass/@qcode='icls:video']/d:contentMeta/d:description[@role='descRole:audio']"/>
<xsl:if test=".=''"><xsl:text> </xsl:text></xsl:if>
</xsl:template>
</xsl:stylesheet>


Somehow this isn't working for me and I don't understand why.


No comments:

Post a Comment