2016-04-01 12 views
0
<?xml version="1.0" encoding="UTF-8"?> 
<clientlist> 

    <client> 
    <data key="id" value="111" /> 
    <data key="name" value="The Parlotones" /> 
    <data key="genre" value="Rock/Alternative" /> 
    <data key="description" value="The Parlotones are known for their electric, polished stage performances delivered against the backdrop of their deftly crafted and darkly romantic lyrics." /> 
    <data key="performanceday" value="Sunday" /> 
    <data key="performancetime" value="01PM-03PM" /> 
    <data key="picture" value="the-parlotones.jpg" /> 
    </client> 

    <client> 
    <data key="id" value="222" /> 
    <data key="name" value="ShortStraw" /> 
    <data key="genre" value="Folk/Acoustic" /> 
    <data key="description" value="Shortstraw are a joburg based band making waves on the national indie music scene in a big way." /> 
    <data key="performanceday" value="Sunday" /> 
    <data key="performancetime" value="03PM-05PM" /> 
    <data key="picture" value="shortstraw.jpg" /> 
    </client> 

    <client> 
    <data key="id" value="333" /> 
    <data key="name" value="Gangs of Ballet" /> 
    <data key="genre" value="Dance/Club" /> 
    <data key="description" value="Their music, which combines their fresh energy with their musically intriguing melodies and arrangements, has a hauntingly anthemic sound." /> 
    <data key="performanceday" value="Saturday" /> 
    <data key="performancetime" value="11AM-01PM" /> 
    <data key="picture" value="gangs-of-ballet.jpg" /> 
    </client> 

</clientlist> 

私は助けが出力されて、XSLとBASHを使用して、私の出力ファイルに、デジタル時代に、私のソースファイルから例えば(15:00)3つのPM/3AM時間を変換たいXML文書。デジタル時間に文字列の書式を設定する

これは、私は、XSLで、これまで持っているものです。

<xsl:if test="not(PM)"> 
    <starts> 
     <xsl:value-of select="number(substring before(data[@key='performancetime']/@value, '-'))" ></xsl:value-of> 
    </starts> 

この結果はNaNの値が全て「開始」に登場し、回「終了」です。

私は本当に、いくつかの助けが必要ありがとう:)

+0

入力の例(または2つ)を表示してください。 –

+0

@ michael.hor257k入力ファイルを追加しました。 – KhanyisileC

+0

http://stackoverflow.com/help/someone-answers –

答えて

0

は、あなたは開始時刻と終了時刻のための分離、それを呼び出すことができ、変換を行うためにという名前のテンプレートを作成することを検討してください。私は、その後、あなたは開始時間のために、このようにそれを呼び出すことができます(つまり、フォーム「hhAM」または「hhPM」である)

<xsl:template name="convertTime"> 
    <xsl:param name="time" /> 
    <xsl:choose> 
     <xsl:when test="contains($time, 'PM')"><xsl:value-of select="number(substring($time, 1, 2)) + 12" /></xsl:when> 
     <xsl:otherwise><xsl:value-of select="substring($time, 1, 2)" /></xsl:otherwise> 
    </xsl:choose> 
    <xsl:text>:00</xsl:text> 
</xsl:template> 

を入力するだけで数分時間の要素が含まれ、そしてません仮定を作っています例

<xsl:call-template name="convertTime"> 
    <xsl:with-param name="time" select="substring-before(data[@key = 'performancetime']/@value, '-')" /> 
</xsl:call-template> 

このXSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="xml" indent="yes" /> 

    <xsl:template match="client"> 
     <xsl:variable name="allTimes" select="data[@key = 'performancetime']/@value" /> 
     <times> 
     <start> 
      <xsl:call-template name="convertTime"> 
       <xsl:with-param name="time" select="substring-before($allTimes, '-')" /> 
      </xsl:call-template> 
     </start> 
     <end> 
      <xsl:call-template name="convertTime"> 
       <xsl:with-param name="time" select="substring-after($allTimes, '-')" /> 
      </xsl:call-template> 
     </end> 
     </times> 
    </xsl:template> 

    <xsl:template name="convertTime"> 
     <xsl:param name="time" /> 
     <xsl:choose> 
      <xsl:when test="contains($time, 'PM')"><xsl:value-of select="number(substring($time, 1, 2)) + 12" /></xsl:when> 
      <xsl:otherwise><xsl:value-of select="substring($time, 1, 2)" /></xsl:otherwise> 
     </xsl:choose> 
     <xsl:text>:00</xsl:text> 
    </xsl:template> 
</xsl:stylesheet> 
0

を試してみてくださいために私はあなたがの線に沿ってそれを試してお勧めします:

<xsl:template match="client"> 
    ... 
    <xsl:variable name="times" select="data[@key='performancetime']/@value"/> 
    <starts> 
     <xsl:call-template name="time24"> 
      <xsl:with-param name="time" select="substring-before($times, '-')" /> 
      </xsl:call-template> 
     </starts> 
     <ends> 
      <xsl:call-template name="time24"> 
       <xsl:with-param name="time" select="substring-after($times, '-')" /> 
      </xsl:call-template> 
    </ends> 
    ... 
</xsl:template> 

<xsl:template name="time24"> 
    <xsl:param name="time" /> 
    <xsl:variable name="h12" select="substring($time, 1, 2)"/> 
    <xsl:variable name="pm" select="contains($time,'P')"/> 
    <xsl:variable name="h24" select="$h12 mod 12 + 12*$pm"/> 
    <xsl:value-of select="format-number($h24, '00')"/> 
    <xsl:text>:00</xsl:text> 
</xsl:template> 
関連する問題