1

我有以下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>

对于以 DisplayName 作为发布日期和审查日期的 FilterCatergories,我想更改 Value 节点的日期格式

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 的新手,不太确定如何实现这一点。任何帮助将不胜感激。

谢谢你。

4

2 回答 2

0

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>
于 2013-11-10T23:56:54.640 回答
-1

([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})

用。。。来代替

\3\2\1 \4:\5

传入格式是否固定?XSD 日期时间?或者可能会有所不同?dateTime 可能有像 +/-02:30 这样的时区,而不是 Z。您应该考虑到它们。

于 2013-11-10T19:16:32.580 回答