I am working on an XSLT version 1.0 (apologies, I know 2.0 is much better!) and thanks to this brilliant community actually got somewhere. I am now stuck again. I am trying to convert this raw and less than attractive XML to a .csv:
<transmissions>
<ES_TRANSMISSION>
<tx_txblocks>
<ES_TXBLOCK>
<txb_announcedtime>
<ESP_TIMEDURATION time="25:00:00.000" tvdayhours="25" hours="1" minutes="00" />
</txb_announcedtime>
<duration>
<ESP_TIMEDURATION duration="50:00.000" />
</duration>
<product>
<ES_PRODUCT p_product_calculatedbroadcasttitle="4" />
</product>
</ES_TXBLOCK>
</tx_txblocks>
<tx_date>
<ESP_DATE date="2019-10-12" dateindays="43383" day="12" dayname="Saturday" month="10" monthname="October" productionweeknumber="41" weekNumberYear="2019" weekdaynumber="6" weeknumber="41" year="2019" />
</tx_date>
<tx_duration>
<ESP_TIMEDURATION duration="50:00.000" hours="0" minutes="50" />
</tx_duration>
<tx_channel>
<ESP_CHANNEL name="Channel A">
<popupLookups />
</ESP_CHANNEL>
</tx_channel>
</ES_TRANSMISSION>
<ES_TRANSMISSION>
<tx_txblocks>
<ES_TXBLOCK>
<txb_announcedtime>
<ESP_TIMEDURATION time="25:50:00.000" tvdayhours="25" hours="1" minutes="50" />
</txb_announcedtime>
<duration>
<ESP_TIMEDURATION duration="45:00.000" />
</duration>
<product>
<ES_PRODUCT p_product_calculatedbroadcasttitle="5" />
</product>
</ES_TXBLOCK>
</tx_txblocks>
<tx_date>
<ESP_DATE date="2019-10-12" dateindays="43383" day="12" dayname="Saturday" month="10" monthname="October" productionweeknumber="41" weekNumberYear="2019" weekdaynumber="6" weeknumber="41" year="2019" />
</tx_date>
<tx_duration>
<ESP_TIMEDURATION duration="45:00.000" hours="0" minutes="45" />
</tx_duration>
<tx_channel>
<ESP_CHANNEL name="Channel A">
<popupLookups />
</ESP_CHANNEL>
</tx_channel>
</ES_TRANSMISSION>
</transmissions>
The third party has some requirements on the .csv, such as always needing two numbers (sorted) and loads of commas because....why not!
But every time I try a for-each to get it to report on more than the first item on the list it comes back with NaN. Below is the XSLT I have built (apologies for it being so basic) that works, but only takes the first item into consideration. I have tried various <xsl:for-each>
for it, but every time it breaks it.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output encoding="utf-8" method="text" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:value-of select="format-number(transmissions/ES_TRANSMISSION/tx_date/ESP_DATE/@day, '00')"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="format-number(transmissions/ES_TRANSMISSION/tx_date/ESP_DATE/@month, '00')"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="transmissions/ES_TRANSMISSION/tx_date/ESP_DATE/@year"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="format-number(transmissions/ES_TRANSMISSION/tx_txblocks/ES_TXBLOCK/txb_announcedtime/ESP_TIMEDURATION/@hours, '00')"/>
<xsl:text>:</xsl:text><xsl:value-of select="transmissions/ES_TRANSMISSION/tx_txblocks/ES_TXBLOCK/txb_announcedtime/ESP_TIMEDURATION/@minutes"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="format-number(transmissions/ES_TRANSMISSION/tx_duration/ESP_TIMEDURATION/@hours, '00')"/><xsl:text>:</xsl:text>
<xsl:value-of select="format-number(transmissions/ES_TRANSMISSION/tx_duration/ESP_TIMEDURATION/@minutes, '00')"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="translate(transmissions/ES_TRANSMISSION/tx_txblocks/ES_TXBLOCK/product/ES_PRODUCT/@p_product_calculatedbroadcasttitle, '.,', '')"/>
<xsl:text>,,,,,,,,,,,,,,,</xsl:text>
<xsl:text>TEST</xsl:text>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="ESP_DATE" mode="full">
<xsl:value-of select="@day"/>
<xsl:text>00</xsl:text>
</xsl:template>
<xsl:template match="ESP_DATE" mode="full">
<xsl:text>00</xsl:text>
<xsl:value-of select="@month"/>
</xsl:template>
<xsl:template match="ESP_TIMEDURATION" mode="full">
<xsl:text>00</xsl:text>
<xsl:value-of select="@hour"/>
</xsl:template>
<xsl:template match ="ES_TRANSMISSION"/>
<xsl:template match="ES_PRODUCT" mode="full"/>
</xsl:stylesheet>
Any hints or guidance would be greatly appreciated. And then I will leave you all alone for a bit while I try to talk people I work with to use 2.0 because I have this massive reference book that I know would be extremely handy!