XSLT - 提取字符串值和格式日期



我有以下XML

 <?xml version="1.0" encoding="utf-8"?>
<FilterPanel>
<FilterCategory DisplayName="Publication Date" ShowMoreLink="True">
<Filters>
  <Filter>
    <Value>Any Publication Date</Value>
    <Tooltip>Any Publication Date</Tooltip>
    <Selection>Implied</Selection>
    <Count></Count>
    <Percentage></Percentage>
  </Filter>
  <Filter>
    <Value>Before 2013-11-08T03:49:32.4999680Z</Value>
    <Tooltip>Before 2013-11-08T03:49:32.4999680Z</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
  <Filter>
    <Value>From 2013-11-08T03:49:32.4999680Z to 2013-11-08T09:46:47.4999808Z</Value>
    <Tooltip>From 2013-11-08T03:49:32.4999680Z to 2013-11- 
08T09:46:47.4999808Z</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
  <Filter>
    <Value>From 2013-11-08T09:46:47.4999808Z to 2013-11-08T16:23:55.9998464Z</Value>
    <Tooltip>From 2013-11-08T09:46:47.4999808Z to 2013-11-   
        08T16:23:55.9998464Z</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
  <Filter>
    <Value>2013-11-08T16:23:55.9998464Z or later</Value>
    <Tooltip>2013-11-08T16:23:55.9998464Z or later</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
</Filters>
</FilterCategory>
 <FilterCategory DisplayName="Review Date" ShowMoreLink="True">
<Filter>SameasPublciationDateOutput</Filter>
</FilterCategory>
<FilterCategory DisplayName="TEST" ShowMoreLink="True">
<Filter></Filter>
</FilterCategory>
</FilterPanel>

对于以显示名称作为发布日期和审阅日期的过滤器类别,我希望更改"值"节点的日期格式

DDMMYYYY HH:MM

给定值的格式。

输出应如下所示:

<FilterCategory DisplayName="Publication Date" ShowMoreLink="True">
<Filters>
  <Filter>
    <Value>Any Publication Date</Value>
    <Tooltip>Any Publication Date</Tooltip>
    <Selection>Implied</Selection>
    <Count></Count>
    <Percentage></Percentage>
  </Filter>
  <Filter>
    <Value>Before 08-11-2013 03:49</Value>
    <Tooltip>Before 08-11-2013 03:49</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
  <Filter>
    <Value>From 08-11-2013 03:49 to 08-11-2013 09:46</Value>
    <Tooltip>From 08-11-2013 03:49 to 08-11-2013 09:46</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
  <Filter>
    <Value>08-11-2013 09:46 to 08-11-2013 16:23</Value>
    <Tooltip>08-11-2013 09:46 to 08-11-2013 16:23</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
  <Filter>
    <Value>08-11-2013 16:23 or later</Value>
    <Tooltip>08-11-2013 16:23 or later</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
</Filters>

我是 XSLT 的新手,不太确定如何实现这一点。任何帮助将不胜感激。

谢谢。

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:template match="@*|node()">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()" />
      </xsl:copy>
   </xsl:template>
   <xsl:template match="text()[contains(.,'T') and contains(.,'Z')]" name="T">
      <xsl:param name="t" select="." />
      <xsl:variable name="a" select="substring-before($t,'T')" />
      <xsl:variable name="l" select="string-length($a)" />
      <xsl:variable name="d" select="substring($a,$l - 1,2)" />
      <xsl:variable name="m" select="substring($a,$l -4,2)" />
      <xsl:variable name="y" select="substring($a,$l -9,4)" />
      <xsl:variable name="b" select="substring-after($t,'T')" />
      <xsl:variable name="c" select="substring-before($b,'Z')" />
      <xsl:variable name="z" select="substring-after($b,'Z')" />
      <xsl:value-of select="concat(substring($a,1,$l -10),$d,'-',$m,'-',$y,' ', substring($c,1,5),' ',$z)" />
   </xsl:template>
   <xsl:template match="text()[contains(.,'T') and contains(.,'Z') and contains(.,' to ')]" priority="2">
      <xsl:call-template name="T">
         <xsl:with-param name="t" select="substring-before(.,' to ')" />
      </xsl:call-template>
      <xsl:text>to</xsl:text>
      <xsl:call-template name="T">
         <xsl:with-param name="t" select="substring-after(.,' to ')" />
      </xsl:call-template>
   </xsl:template>
</xsl:stylesheet>

输入:

<FilterPanel>
<FilterCategory DisplayName="Publication Date" ShowMoreLink="True">
<Filters>
  <Filter>
    <Value>Any Publication Date</Value>
    <Tooltip>Any Publication Date</Tooltip>
    <Selection>Implied</Selection>
    <Count></Count>
    <Percentage></Percentage>
  </Filter>
  <Filter>
    <Value>Before 2013-11-08T03:49:32.4999680Z</Value>
    <Tooltip>Before 2013-11-08T03:49:32.4999680Z</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
  <Filter>
    <Value>From 2013-11-08T03:49:32.4999680Z to 2013-11-08T09:46:47.4999808Z</Value>
    <Tooltip>From 2013-11-08T03:49:32.4999680Z to 2013-11-08T09:46:47.4999808Z</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
  <Filter>
    <Value>From 2013-11-08T09:46:47.4999808Z to 2013-11-08T16:23:55.9998464Z</Value>
    <Tooltip>From 2013-11-08T09:46:47.4999808Z to 2013-11-08T16:23:55.9998464Z</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
  <Filter>
    <Value>2013-11-08T16:23:55.9998464Z or later</Value>
    <Tooltip>2013-11-08T16:23:55.9998464Z or later</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
</Filters>
</FilterCategory>
 <FilterCategory DisplayName="Review Date" ShowMoreLink="True">
<Filter>SameasPublciationDateOutput</Filter>
</FilterCategory>
<FilterCategory DisplayName="TEST" ShowMoreLink="True">
<Filter></Filter>
</FilterCategory>
</FilterPanel>

输出

<?xml version="1.0" encoding="utf-8"?><FilterPanel>
<FilterCategory DisplayName="Publication Date" ShowMoreLink="True">
<Filters>
  <Filter>
    <Value>Any Publication Date</Value>
    <Tooltip>Any Publication Date</Tooltip>
    <Selection>Implied</Selection>
    <Count/>
    <Percentage/>
  </Filter>
  <Filter>
    <Value>Before 08-11-2013 03:49 </Value>
    <Tooltip>Before 08-11-2013 03:49 </Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
  <Filter>
    <Value>From 08-11-2013 03:49  to 08-11-2013 09:46 </Value>
    <Tooltip>From 08-11-2013 03:49  to 08-11-2013 09:46 </Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
  <Filter>
    <Value>From 08-11-2013 09:46  to 08-11-2013 16:23 </Value>
    <Tooltip>From 08-11-2013 09:46  to 08-11-2013 16:23 </Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
  <Filter>
    <Value>08-11-2013 16:23  or later</Value>
    <Tooltip>08-11-2013 16:23  or later</Tooltip>
    <Selection>Deselected</Selection>
    <Count>1568</Count>
    <Percentage>0.25</Percentage>
  </Filter>
</Filters>
</FilterCategory>
 <FilterCategory DisplayName="Review Date" ShowMoreLink="True">
<Filter>SameasPublciationDateOutput</Filter>
</FilterCategory>
<FilterCategory DisplayName="TEST" ShowMoreLink="True">
<Filter/>
</FilterCategory>
</FilterPanel>

([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}).([0-9]*)(Z|[+-]?[0-9]{2}:[0-9]{2})

替换为

321 4:5

传入格式是固定的吗?XSD 日期时间 ?或者可能不同?dateTime 可以具有 +/-02:30 等时区,而不是 Z。您应该考虑它们。

相关内容

  • 没有找到相关文章