0

Currently I output to txt files a large number of product codes and various attributes held within them. "Item End Date" is one of the attributes outputted.

Is there a way to query this attribute value to say only perform the XSL functions if Item End Date is after today's date?

I am using Altova if that helps.

XML:

 <Agility>
<group>
    <product id="295826" subtype="CMS Product" created="20/04/12" modified="03/03/15">
        <attribute definition_id="26" modified="20/04/12" is_name="true" is_identifier="true" scope="global" type="text">
            <data language="English" label="CMS Product Name">012345</data>
        </attribute>
        <attribute definition_id="278" modified="28/08/08" scope="global" type="datetime">
            <data language="English" label="Item End Date">01/01/99</data>
        </attribute>
    </product>
</group>

XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>


<xsl:template match="product[@subtype = 'CMS Product']">

<xsl:for-each select="attribute">
  <xsl:if test="@definition_id = 278"> 
    <xsl:value-of select="data" />
  </xsl:if>
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • On its own, XSLT 1.0 provides no way to get the current date. You could pass the current date as a parameter to the stylesheet at runtime, or - if your specific XSLT processor supports it - use an extension function. Altova is not an XSLT processor. Get the name of the actual processor you are using, see here how: http://stackoverflow.com/questions/25244370/how-can-we-check-that-which-xslt-processor-uses-as-default-in-solr/25245033?s=1|0.1827#25245033 – michael.hor257k Apr 24 '15 at 13:31
  • Thanks for the reponse Michael - Confirmed Altova GmbH Version 2.0 – Jimmy Sumpter Apr 24 '15 at 14:01
  • In XSLT 2.0 you can use the `current-date()` function. However, before you can compare this to your `Item End Date` values, you must convert them to valid xs:date format (e.g. "2015-04-24"). If, as it seems, your data has 2-digit years and can go back to 1999 or earlier, that's going to take some work. – michael.hor257k Apr 24 '15 at 14:21
  • We can assume no end dates go further back than 2000, so /99 will always be 2099. This causes me a problem every time I import the outputted files into Excel! – Jimmy Sumpter Apr 24 '15 at 14:27
  • And your current date format Is? "01/01/99" is ambiguous. – michael.hor257k Apr 24 '15 at 14:34
  • Sorry that was a poor example, date format is: dd/mm/yy – Jimmy Sumpter Apr 24 '15 at 14:39

1 Answers1

1

Try it this way?

<xsl:template match="product">
    <xsl:variable name="end" select="attribute/data[@label='Item End Date']" />
    <xsl:variable name="end-date" select="xs:date(concat('20', substring($end, 7, 2), '-', substring($end, 4, 2), '-',substring($end, 1, 2)))" />
    <xsl:if test="$end-date gt current-date()">
        <!-- do your processing here -->
    </xsl:if>
</xsl:template>
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51