[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Basic template matching issues - I think?


Subject: RE: [xsl] Basic template matching issues - I think?
From: An OldBloke <neil_owens@xxxxxxxxxxx>
Date: Tue, 20 Nov 2012 17:55:39 +0000

Chaps

Apologies for my myopicness earlier.

I've made some progress but am still seeing a RegEx error generated.  The
RegEx itself works in test websites(minus the double curly brackets) but gives
the following error:-

C:\>java -jar saxon9he.jar -o Result.xml text.xml regextime.xslt
Error at xsl:analyze-string on line 13 of regextime.xslt:
  XTDE1140: Error in regular expression: net.sf.saxon.trans.XPathException:
Error at
  character 8 in regular expression "(\d{2})\/(\d{2})\/(\d{4}) (\d{...":
invalid
 escape sequence
Failed to compile stylesheet. 1 error detected.



I'm looking to re-format the time attribute to a datetime format - from
'12/11/2012 6:12:04 AM' to '2012-22-12T06:12:04' in this case.  Unless anyone
knows a better way of re-formatting date/times? - I'm open to ideas.


XML:
<Log Device="SERVER1">
<myCommand Command="test" Time="12/11/2012 6:12:04 AM" Port="9999"
IP="1.1.1.1">
<Struct>
<OUTID>SERVER2</OUTID>
<INID>SERVER3</INID>
<test>
<item>2</item>
<GUID>21EC2020-3AEA-1069-A2DD-08002B30309D</GUID>
<status>OK</status>
</test>
</Struct>
</myCommand>
</Log>

XSL:
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" name="TextFormat"
omit-xml-declaration="yes"/>


<xsl:template match="Log">
    <xsl:apply-templates select="myCommand"/>
</xsl:template>

<xsl:template match="myCommand">
    <myCommand>
        <xsl:element name="Command"><xsl:value-of
select="@Command"/></xsl:element>
        <xsl:analyze-string select="Time"
regex="(\d{{2}})\/(\d{{2}})\/(\d{{4}}) (\d{{1,2}}):(\d{{2}}):(\d{{2}})">
            <xsl:matching-substring>
                <xsl:value-of select="concat(string(number(regex-group(3))),
'-',
                                 string(number(regex-group(2))), '-',
                                 string(number(regex-group(1))), 'T',
                                 string(format-number(number(regex-group(4)),
'00')), ':',
                                 string(number(regex-group(5))), ':',
                                 string(number(regex-group(6))))" />
            </xsl:matching-substring>
        </xsl:analyze-string>
        <xsl:element name="Port"><xsl:value-of select="@Port"/></xsl:element>
    </myCommand>
</xsl:template>
</xsl:stylesheet>


Current Thread