2017-12-21 20 views
0

XSL을 사용하여 날짜 형식을 yyyy-mm-dd에서 dd-mmm-yyyy으로 변경해야하는 요구 사항이 있습니다.XSL을 사용하여 속성 값 변경

저는 날짜의 가치를 얻고 그것을 변경하기위한 논리를 작성했습니다. 그러나 어떻게 든 가치는 변하지 않습니다.

요청 및 XSL

도 여기에서 찾을 수 있습니다 : Change the Date format

XML 입력

<params> 
<param name ="query" > 
    <queryData> 
     <parameter index ="0" value ="2017-12-06" dataType="java.lang.String"/> 
     <parameter index ="1" value ="2017-12-03" dataType="java.lang.String"/>  
    </queryData> 
</param> 
</params> 

XSLT 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" /> 
    <xsl:strip-space elements="*" /> 
    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()" /> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="params/param/queryData/parameter[@value='*'][normalize-space()]"> 
     <xsl:copy> 
      <xsl:call-template name="reformat-date"> 
       <xsl:with-param name="date" select="." /> 
      </xsl:call-template> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template name="reformat-date"> 
     <xsl:param name="date" /> 
     <xsl:variable name="dd" select="substring-after(substring-after($date, '-'), '-')" /> 
     <xsl:variable name="mmm" select="substring-before(substring-after($date, '-'),  '-')" /> 
     <xsl:variable name="yyyy" select="substring-before($date, '-')" /> 
     <xsl:value-of select="$dd" /> 
     <xsl:text>-</xsl:text> 
     <xsl:choose> 
      <xsl:when test="$mmm = '01'">JAN</xsl:when> 
      <xsl:when test="$mmm = '02'">FEB</xsl:when> 
      <xsl:when test="$mmm = '03'">MAR</xsl:when> 
      <xsl:when test="$mmm = '04'">APR</xsl:when> 
      <xsl:when test="$mmm = '05'">MAY</xsl:when> 
      <xsl:when test="$mmm = '06'">JUN</xsl:when> 
      <xsl:when test="$mmm = '07'">JUL</xsl:when> 
      <xsl:when test="$mmm = '08'">AUG</xsl:when> 
      <xsl:when test="$mmm = '09'">SEP</xsl:when> 
      <xsl:when test="$mmm = '10'">OCT</xsl:when> 
      <xsl:when test="$mmm = '11'">NOV</xsl:when> 
      <xsl:when test="$mmm = '12'">DEC</xsl:when> 
     </xsl:choose> 
     <xsl:text>-</xsl:text> 
     <xsl:value-of select="$yyyy" /> 
    </xsl:template> 
</xsl:stylesheet> 
+0

외부에 대한 링크를 제공하는 문제를 나타내는 코드 (XML 및 XSLT)를 게시, 그리고 제발이 필요하므로 속성을 만들 수 있습니다 대지. – AntonH

답변

2

당신이 당신을 속성을 변경하려면 속성과 일치하도록 일치 패턴을 조정해야하며 그렇지 않은 경우에는 그렇지 않습니다. D는

<xsl:template match="params/param/queryData/parameter/@value"> 
    <xsl:attribute name="{name()}"> 
     <xsl:call-template name="reformat-date"> 
      <xsl:with-param name="date" select="." /> 
     </xsl:call-template> 
    </xsl:attribute> 
</xsl:template> 

대신

<xsl:template match="params/param/queryData/parameter[@value='*'][normalize-space()]"> 
    <xsl:copy> 
     <xsl:call-template name="reformat-date"> 
      <xsl:with-param name="date" select="." /> 
     </xsl:call-template> 
    </xsl:copy> 
</xsl:template> 

http://xsltransform.net/bEJaofn/1