Hi,
I am trying to write a error log text file using xml as a data file and xsl as a validation file. attached are my input files. I stuckup in converting them.. please advice.
thanks in advance,
siva
below are my files information.
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="Validations_Dummy.xsl"?>
<Project>
<work>
<row>
<ChkDate>13252009</ChkDate>
<ChkLength>alpha numaric with lengh</ChkLength>
<ChkContains>one</ChkContains>
<ChkNumber>800</ChkNumber>
</row>
<row>
<ChkDate>3252009</ChkDate>
<ChkLength>alpha numaric with lenghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</ChkLength>
<ChkContains>tingting</ChkContains>
<ChkNumber>xyz</ChkNumber>
</row>
</work>
<Prep>
<ReportName>
<RNValue>one</RNValue>
<RNValue>two</RNValue>
<RNValue>three</RNValue>
<RNValue>four</RNValue>
</ReportName>
</Prep>
</Project>
<?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"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="work">
<xsl:apply-templates select="rowrow"/>
</xsl:template>
<xsl:template match="row" name="rowrow">
<xsl:apply-templates select="ChkDate"/>
<xsl:apply-templates select="ChkLength"/>
<xsl:apply-templates select="ChkContains"/>
<xsl:apply-templates select="ChkNumber"/>
</xsl:template>
<xsl:template match="ChkDate">
<xsl:call-template name="checkDate">
<xsl:with-param name="theDate" select="current()"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="ChkLength">
<xsl:call-template name="CheckLength">
<xsl:with-param name="min" select="1"/>
<xsl:with-param name="max" select="50"/>
<xsl:with-param name="chkValue" select="current()"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="ChkContains">
<xsl:call-template name="CheckContains">
<xsl:with-param name="preDefNode" select="Project/Prep/ReportName"/>
<xsl:with-param name="chkValue" select="current()"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="ChkNumber">
<xsl:call-template name="CheckNumber">
<xsl:with-param name="chkValue" select="current()"/>
</xsl:call-template>
</xsl:template>
<!-- Predefined Templates for Validations-->
<xsl:template name="CheckLength">
<xsl:param name="min"/>
<xsl:param name="max"/>
<xsl:param name="chkValue"/>
<xsl:choose>
<xsl:when test="string-length($chkValue) > $min and string-length($chkValue) < $max">
<xsl:text></xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$chkValue"/>
<xsl:text>~Length is not in Range
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="CheckNumber">
<xsl:param name="chkValue"/>
<xsl:choose>
<xsl:when test="not(number($chkValue))">
<xsl:value-of select="$chkValue"/>
<xsl:text>~Is Not a Number
</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="CheckContains">
<xsl:param name="preDefNode"/>
<xsl:param name="chkValue"/>
<xsl:for-each select="$preDefNode">
<xsl:choose>
<xsl:when test="contains(. ,$chkValue)">
<xsl:text></xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$chkValue"/>
<xsl:text> ~Not a Valid Value
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template name="checkDate">
<xsl:param name="theDate"/>
<xsl:choose>
<!-- First see if the date is the right length, 8 digits -->
<xsl:when test="string-length($theDate) = 8">
<xsl:variable name="mm" select="substring($theDate, 1,2 )"/>
<xsl:variable name="dd" select="substring($theDate, 3,2 )"/>
<xsl:variable name="yyyy" select="substring($theDate, 5,4)"/>
<xsl:choose>
<xsl:when test="string-length($yyyy) != 4 or not(number($yyyy))">
<xsl:value-of select="$yyyy"/>
<xsl:text> is not the correct format.</xsl:text>
<xsl:text> (must have four-digit year)\t</xsl:text>
</xsl:when>
<xsl:when test="string-length($mm) != 2 or not(number($mm)) or number($mm) > 12">
<xsl:value-of select="$mm"/>
<xsl:text> is not the correct format.</xsl:text>
<xsl:text> (Month value should be valid)\t</xsl:text>
</xsl:when>
<xsl:when test="string-length($dd) != 2 or not(number($dd)) or number($dd) > 31">
<xsl:value-of select="$dd"/>
<xsl:text> is not the correct format.</xsl:text>
<xsl:text> (Day value should be valid)\t</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$theDate"/>
<xsl:text>\t</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- bad length -->
<xsl:otherwise>
<xsl:value-of select="$theDate"/>
<xsl:text> is not the correct format.</xsl:text>
<xsl:text> (invalid length)
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Predefined Templates for Validations-->
</xsl:stylesheet>