I'm parsing a RSS feed from a Wordpress blog using the following XSL (this is the relevant snippet) to pump out a JSON. All works fine and dandy when there's a match for each of the below items. However I have a new case where I'm trying to pull from a separate Wordpress blog that is not setup with categories, which generates a null value and thus breaks my script. I'm having crap luck injecting a working conditional statement in the below. Any ideas?
<xsl:template match="item">
{ "title": "<xsl:value-of select="title"/>"
,"link": "<xsl:value-of select="link"/>"
,"date": "<xsl:value-of select="date-converter:getDateFormat(string(pubDate) , 'mmmm d, yyyy')"/>"
,"category": "<xsl:apply-templates select="category"/>"
,"description": "<xsl:call-template name="replace">
<xsl:with-param name="text">
<xsl:value-of select="normalize-space(description/node())"/>
</xsl:with-param>
<xsl:with-param name="replace">"</xsl:with-param>
<xsl:with-param name="by">\"</xsl:with-param>
</xsl:call-template>"
}
<xsl:if test="not(position() = last())">
,
</xsl:if>
Here's a sample of the input data from the RSS. You'll note the null category, which for the other RSS feed would be something like "Events" but for this blog there are not categories because of the way they setup it up (btw this blog isn't mine so I can't change it's structure).
<data>
[
{ "title": "Inventors Forum: Speakers Series"
,"link": "http://innovation.uci.edu/event/inventors-forum-speakers-series/"
,"date": "November 13, 2015"
,"category": ""
,"description": "About Inventors Forum We are an organization of inventors and those who help inventors. We invite you to join us. Mission Statement Inventors Forum is dedicated to assisting and educating early-stage inventors and to providing the environment necessary to safely bring new products ideas to the marketplace. What We Are We are a 501(c)3 nonprofit … <a href=\"http://innovation.uci.edu/event/inventors-forum-speakers-series/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Inventors Forum: Speakers Series</span> <span class=\"meta-nav\">→</span></a>"
}
,
{ "title": "Golden Seeds SoCal Overview & Reception"
,"link": "http://innovation.uci.edu/event/golden-seeds-socal-overview-reception/"
,"date": "November 16, 2015"
,"category": ""
,"description": "Golden Seeds was founded ten years ago, with the goal of raising substantial capital for women-led start-ups. During that time, they have met thousands of companies and have invested $77 million in over 100 companies. Golden Seeds is widely recognized as a leading voice in the movement to propel women entrepreneurs. At the Golden Seeds … <a href=\"http://innovation.uci.edu/event/golden-seeds-socal-overview-reception/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Golden Seeds SoCal Overview & Reception</span> <span class=\"meta-nav\">→</span></a>"
}
,
{ "title": "NHLBI Innovation Conference – West"
,"link": "http://innovation.uci.edu/event/nhlbi-innovation-conference-west/"
,"date": "November 17, 2015"
,"category": ""
,"description": "NHLBI’s Office of Translational Alliances and Coordination (OTAC) hosts the NHLBI Innovation Conference to connect NHLBI-funded companies, investors, strategic partners, and business leaders from the biotech, medical device, and pharmaceutical industries. The Conference showcases NHLBI SBIR and STTR awardees who are developing the next generation of products to diagnose and treat heart, lung, blood, and … <a href=\"http://innovation.uci.edu/event/nhlbi-innovation-conference-west/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">NHLBI Innovation Conference – West</span> <span class=\"meta-nav\">→</span></a>"
}
,
{ "title": "1 Million Cups Irvine"
,"link": "http://innovation.uci.edu/event/1-million-cups-irvine-7/"
,"date": "December 2, 2015"
,"category": ""
,"description": "1 Million Cups is a unique event every Wednesday morning from 8am-9am at The Cove, where we provide free coffee and tea. The two startups give a 6 minute presentation spot, then give the live audience of 50+ people 20 minutes to ask questions, give feedback, and act as a focus group with the intention … <a href=\"http://innovation.uci.edu/event/1-million-cups-irvine-7/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">1 Million Cups Irvine</span> <span class=\"meta-nav\">→</span></a>"
}
,
{ "title": "1 Million Cups Irvine"
,"link": "http://innovation.uci.edu/event/1-million-cups-irvine-8/"
,"date": "December 9, 2015"
,"category": ""
,"description": "1 Million Cups is a unique event every Wednesday morning from 8am-9am at The Cove, where we provide free coffee and tea. The two startups give a 6 minute presentation spot, then give the live audience of 50+ people 20 minutes to ask questions, give feedback, and act as a focus group with the intention … <a href=\"http://innovation.uci.edu/event/1-million-cups-irvine-8/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">1 Million Cups Irvine</span> <span class=\"meta-nav\">→</span></a>"
}
,
{ "title": "1 Million Cups Irvine"
,"link": "http://innovation.uci.edu/event/1-million-cups-irvine-10/"
,"date": "December 16, 2015"
,"category": ""
,"description": "1 Million Cups is a unique event every Wednesday morning from 8am-9am at The Cove, where we provide free coffee and tea. The two startups give a 6 minute presentation spot, then give the live audience of 50+ people 20 minutes to ask questions, give feedback, and act as a focus group with the intention … <a href=\"http://innovation.uci.edu/event/1-million-cups-irvine-10/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">1 Million Cups Irvine</span> <span class=\"meta-nav\">→</span></a>"
}
]
</data>