私はこのコードを実行しています。ここでは、自分のニーズに応じて '@datetime'で日時をフォーマットしています。 このコードは完全に機能します。しかしXSLT 1.0テンプレートと変数の作成
<?xml version ='1.0' encoding='UTF-8'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match ="transcript/call">
<xsl:variable name="datestr" select="substring-before(@datetime,' UTC')" />
<xsl:variable name="MMM" select="format-number(string-length(substring-before('JanFebMarAprMayJunJulAugSepOctNovDec',substring(substring($datestr,1,3),1,3))) div 3 + 1,'00')"/>
<xsl:variable name="D" select="format-number(floor(substring($datestr,5,1)),'00')" />
<xsl:variable name="YYYY" select="substring($datestr,8,4)" />
<xsl:variable name="hh" select="substring($datestr,13,2)" />
<xsl:variable name="mm" select="substring($datestr,16,2)" />
<xsl:variable name="ss" select="substring($datestr,19,2)" />
<!-- <xsl:variable name="DateTimeFormatted" select="concat($YYYY,'-', $MMM, '-', $D, 'T', $hh, ':', $mm, ':', $ss, 'Z')" /> -->
Your chat transcript from Univ100 @ Student dated <xsl:value-of select="concat($YYYY,'-', $MMM, '-', $D, 'T', $hh, ':', $mm, ':', $ss, 'Z')" />
-------------------------------------------------------------------------------------
</xsl:template>
<xsl:template match ="transcript/say">
<xsl:if test ="./@source ='customer'">
[<xsl:value-of select ="@datetime" />] <xsl:value-of select ="@name" /> says: <xsl:value-of select ="." disable-output-escaping="yes" /></xsl:if>
<xsl:if test ="./@source ='agent'">
[<xsl:value-of select ="@datetime" />] Student Officer says: <xsl:value-of select ="." disable-output-escaping="yes" /></xsl:if>
<xsl:if test ="./@source ='system'">
<xsl:if test ="./@display ='true'">
[<xsl:value-of select ="@datetime" />] System: <xsl:value-of select ="." disable-output-escaping="yes" />
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match ="transcript/url">
<xsl:if test ="./@source ='customer'">
[<xsl:value-of select ="@datetime" />] <xsl:value-of select ="@name" /> sends: <xsl:value-of select ="." disable-output-escaping="yes" />
</xsl:if>
<xsl:if test ="./@source ='agent'">
[<xsl:value-of select ="@datetime" />] Student Officer sends: <xsl:value-of select ="." disable-output-escaping="yes" />
</xsl:if>
<xsl:if test ="./@source ='system'">
<xsl:if test ="./@display ='true'">
[<xsl:value-of select ="@datetime" />] System: <xsl:value-of select ="." disable-output-escaping="yes" />
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match ="transcript/event">
</xsl:template>
<xsl:template match ="parameters">
Univ100
</xsl:template>
</xsl:stylesheet>
、パラメータを受け取り、フォーマットされた文字列を返すのフォーマットのための別のテンプレートを作るために、私はそれを複数回使用することができますように、私は、以下の変更を加えたときに必要に応じて、このチャット記録。
私は以下の変更を加えましたが、コードは動作しません。
<?xml version ='1.0' encoding='UTF-8'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template name="formatter">
<xsl:param name="datestr"/>
<!-- <xsl:variable name="datestr" select="substring-before(@datetime,' UTC')" /> -->
<xsl:variable name="MMM" select="format-number(string-length(substring-before('JanFebMarAprMayJunJulAugSepOctNovDec',substring(substring($datestr,1,3),1,3))) div 3 + 1,'00')"/>
<xsl:variable name="D" select="format-number(floor(substring($datestr,5,1)),'00')" />
<xsl:variable name="YYYY" select="substring($datestr,8,4)" />
<xsl:variable name="hh" select="substring($datestr,13,2)" />
<xsl:variable name="mm" select="substring($datestr,16,2)" />
<xsl:variable name="ss" select="substring($datestr,19,2)" />
<!-- <xsl:variable name="DateTimeFormatted" select="concat($YYYY,'-', $MMM, '-', $D, 'T', $hh, ':', $mm, ':', $ss, 'Z')" /> -->
<xsl:value-of select="concat($YYYY,'-', $MMM, '-', $D, 'T', $hh, ':', $mm, ':', $ss, 'Z')" />
</xsl:template>
<xsl:template match ="transcript/call">
<xsl:variable name="returnValue">
<xsl:call-template name="formatter">
<xsl:with-param name="datestr" select="@datetime"></xsl:with-param>
</xsl:call-template>
</xsl:variable>
Your chat transcript from Univ100 @ Student dated <xsl:value-of select="$returnValue"/>
-------------------------------------------------------------------------------------
</xsl:template>
<xsl:template match ="transcript/say">
<xsl:if test ="./@source ='customer'">
[<xsl:value-of select ="@datetime" />] <xsl:value-of select ="@name" /> says: <xsl:value-of select ="." disable-output-escaping="yes" /></xsl:if>
<xsl:if test ="./@source ='agent'">
[<xsl:value-of select ="@datetime" />] Student Officer says: <xsl:value-of select ="." disable-output-escaping="yes" /></xsl:if>
<xsl:if test ="./@source ='system'">
<xsl:if test ="./@display ='true'">
[<xsl:value-of select ="@datetime" />] System: <xsl:value-of select ="." disable-output-escaping="yes" />
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match ="transcript/url">
<xsl:if test ="./@source ='customer'">
[<xsl:value-of select ="@datetime" />] <xsl:value-of select ="@name" /> sends: <xsl:value-of select ="." disable-output-escaping="yes" />
</xsl:if>
<xsl:if test ="./@source ='agent'">
[<xsl:value-of select ="@datetime" />] Student Officer sends: <xsl:value-of select ="." disable-output-escaping="yes" />
</xsl:if>
<xsl:if test ="./@source ='system'">
<xsl:if test ="./@display ='true'">
[<xsl:value-of select ="@datetime" />] System: <xsl:value-of select ="." disable-output-escaping="yes" />
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match ="transcript/event">
</xsl:template>
<xsl:template match ="parameters">
Univ100
</xsl:template>
</xsl:stylesheet>
私は1.0をXSLTの非常に新しいですし、私はバージョンを変更またはアップグレードするには、他のオプションが用意されていないとして、私は唯一の純粋なXSLT 1.0上で動作することができ、この上で仕事をしなければなりません。これは私がプロジェクトに対して持っている唯一のコントロールです。私はDBサーバー、このXLSTを使用するXMLファイル、またはプロジェクトの他の側面にアクセスすることはできません。
ご協力いただければ幸いです。
XML入力と予想される出力の例を表示してください - [mcve]を参照してください。 XMLに直接アクセスできない場合は、* identity transform *テンプレートを使用して取得してください。 –