首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用XSL样式表解析Google提要中的日期/时间信息

使用XSL样式表解析Google提要中的日期/时间信息
EN

Stack Overflow用户
提问于 2015-02-27 23:08:27
回答 1查看 156关注 0票数 0

在使用样式表解析Google提要中的某些日期/时间字段时,我需要帮助。到目前为止,我得到了很好的帮助,发布在这里:Google Cal XSLT

第二部分是得到离散字段中的日期和时间。这里是原始的XML输出,我了解到它实际上是带有XML包装器的HTML。

代码语言:javascript
复制
    <?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:gCal="http://schemas.google.com/gCal/2005">
  <id>http://www.google.com/calendar/feeds/cqdcu7b550jienqk97ddrdfhpc%40group.calendar.google.com/public/basic</id>
  <updated>2015-02-24T23:02:37.000Z</updated>
  <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
  <title type="text">SB Meetings</title>
  <subtitle type="text">SB Meetings</subtitle>
  <link rel="alternate" type="text/html" href="https://www.google.com/calendar/embed?src=cqdcu7b550jienqk97ddrdfhpc%40group.calendar.google.com"/>
  <link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="https://www.google.com/calendar/feeds/cqdcu7b550jienqk97ddrdfhpc%40group.calendar.google.com/public/basic"/>
  <link rel="http://schemas.google.com/g/2005#batch" type="application/atom+xml" href="https://www.google.com/calendar/feeds/cqdcu7b550jienqk97ddrdfhpc%40group.calendar.google.com/public/basic/batch"/>
  <link rel="self" type="application/atom+xml" href="https://www.google.com/calendar/feeds/cqdcu7b550jienqk97ddrdfhpc%40group.calendar.google.com/public/basic?max-results=25"/>
  <link rel="next" type="application/atom+xml" href="https://www.google.com/calendar/feeds/cqdcu7b550jienqk97ddrdfhpc%40group.calendar.google.com/public/basic?start-index=26&amp;max-results=25"/>
  <author>
    <name>xx.xx@gmail.com</name>
    <email>xx.xx@gmail.com</email>
  </author>
  <generator version="1.0" uri="http://www.google.com/calendar">Google Calendar</generator>
  <openSearch:totalResults>848</openSearch:totalResults>
  <openSearch:startIndex>1</openSearch:startIndex>
  <openSearch:itemsPerPage>25</openSearch:itemsPerPage>
  <gCal:timezone value="America/Los_Angeles"/>
  <gCal:timesCleaned value="0"/>
  <entry>
    <id>http://www.google.com/calendar/feeds/cqdcu7b550jienqk97ddrdfhpc%40group.calendar.google.com/public/basic/_6srj8chl6hhm4oppc9ij8oppcks3gp9n6kom6pb2cdij8c9gcpj3kc9d74ok6dpl8p246gpi6gqkae9j88s3gchl6t24cdhg60rk8di588s2qc9k68qjadpm6oo30c1g60mj2d1i6gs32e1i60pj0c1g</id>
    <published>2015-02-24T23:02:37.000Z</published>
    <updated>2015-02-24T23:02:37.000Z</updated>
    <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
    <title type="html">Project Manager Meeting</title>
    <summary type="html">When: Thu Mar 5, 2015 9:30am to 10:30am&amp;nbsp;
PST&lt;br&gt;

&lt;br&gt;Where: Conference Room NH2/CA Motor City S Vermont 12345@KAIPERM
&lt;br&gt;Event Status: confirmed
&lt;br&gt;Event Description: Chairperson: Resource-Scheduler
Required: Test User 2</summary>
    <content type="html">When: Thu Mar 5, 2015 9:30am to 10:30am 
PST&lt;br /&gt;

&lt;br /&gt;Where: Conference Room NH2/CA Motor City S Vermont 12345@KAIPERM
&lt;br /&gt;Event Status: confirmed
&lt;br /&gt;Event Description: Chairperson: Resource-Scheduler
Required: Test User 2</content>
    <link rel="alternate" type="text/html" href="https://www.google.com/calendar/event?eid=XzZzcmo4Y2hsNmhobTRvcHBjOWlqOG9wcGNrczNncDluNmtvbTZwYjJjZGlqOGM5Z2NwajNrYzlkNzRvazZkcGw4cDI0NmdwaTZncWthZTlqODhzM2djaGw2dDI0Y2RoZzYwcms4ZGk1ODhzMnFjOWs2OHFqYWRwbTZvbzMwYzFnNjBtajJkMWk2Z3MzMmUxaTYwcGowYzFnIGNxZGN1N2I1NTBqaWVucWs5N2RkcmRmaHBjQGc" title="alternate"/>
    <link rel="self" type="application/atom+xml" href="https://www.google.com/calendar/feeds/cqdcu7b550jienqk97ddrdfhpc%40group.calendar.google.com/public/basic/_6srj8chl6hhm4oppc9ij8oppcks3gp9n6kom6pb2cdij8c9gcpj3kc9d74ok6dpl8p246gpi6gqkae9j88s3gchl6t24cdhg60rk8di588s2qc9k68qjadpm6oo30c1g60mj2d1i6gs32e1i60pj0c1g"/>
    <author>
      <name>SB Meetings</name>
      <email>yy.yy@gmail.com</email>
    </author>
  </entry>
  <entry>
    <id>http://www.google.com/calendar/feeds/cqdcu7b550jienqk97ddrdfhpc%40group.calendar.google.com/public/basic/_c9ijacj668sj0or16dh38chmcos3eohk64smcdpm64qjce1k6kq3kc9d64qj0g9h65330dq16kojedq170s3gchl6t24cdhg60rk8di588oiqc9k68q36dhn60o30c1g60mj2d1i6gs32e1i60pj0c1g</id>
    <published>2015-02-24T23:02:37.000Z</published>
    <updated>2015-02-24T23:02:37.000Z</updated>
    <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
    <title type="html">Analyst Meeting</title>
    <summary type="html">When: Thu Feb 19, 2015 9:30am to 10:30am&amp;nbsp;
PST&lt;br&gt;

&lt;br&gt;Where: Conference Room NH4/CA Motor City S Vermont 12345
&lt;br&gt;Event Status: confirmed
&lt;br&gt;Event Description: Chairperson: Resource-Scheduler
Required: Test User 1</summary>
    <content type="html">When: Thu Feb 19, 2015 9:30am to 10:30am 
PST&lt;br /&gt;

&lt;br /&gt;Where: Conference Room NH4/CA Motor City S Vermont 12345
&lt;br /&gt;Event Status: confirmed
&lt;br /&gt;Event Description: Chairperson: Resource-Scheduler
Required: Test User 1</content>
    <link rel="alternate" type="text/html" href="https://www.google.com/calendar/event?eid=X2M5aWphY2o2NjhzajBvcjE2ZGgzOGNobWNvczNlb2hrNjRzbWNkcG02NHFqY2UxazZrcTNrYzlkNjRxajBnOWg2NTMzMGRxMTZrb2plZHExNzBzM2djaGw2dDI0Y2RoZzYwcms4ZGk1ODhvaXFjOWs2OHEzNmRobjYwbzMwYzFnNjBtajJkMWk2Z3MzMmUxaTYwcGowYzFnIGNxZGN1N2I1NTBqaWVucWs5N2RkcmRmaHBjQGc" title="alternate"/>
    <link rel="self" type="application/atom+xml" href="https://www.google.com/calendar/feeds/cqdcu7b550jienqk97ddrdfhpc%40group.calendar.google.com/public/basic/_c9ijacj668sj0or16dh38chmcos3eohk64smcdpm64qjce1k6kq3kc9d64qj0g9h65330dq16kojedq170s3gchl6t24cdhg60rk8di588oiqc9k68q36dhn60o30c1g60mj2d1i6gs32e1i60pj0c1g"/>
    <author>
      <name>SB Meetings</name>
      <email>yy.yy@gmail.com</email>
    </author>
  </entry>
</feed>

我的目标是实现以下输出:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<items>
   <item>
      <title>Project Manager Meeting</title>
      <date>3/5/2015</date>
      <starttime>9:30 AM</starttime>
      <endtime>10:30 AM</endtime>
      <where>Conference Room NH2/CA Motor City S Vermont 12345
</where>
   </item>
   <item>
      <title>Analyst Meeting</title>
      <date>2/19/2015</date>
      <starttime>9:30 AM</starttime>
      <endtime>10:30 AM</endtime>
      <where>Conference Room NH4/CA Motor City S Vermont 12345
</where>
   </item>
</items>

任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-27 23:50:29

这里的想法不是重复已经给出的另一个问题的解决方案,而是专注于从该解决方案中提取数据的问题。考虑:

XSLT1.0

代码语言:javascript
复制
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://www.w3.org/2005/Atom"
exclude-result-prefixes="atom">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
    <items>
        <xsl:for-each select="//atom:entry">
            <item>
                <title>
                    <xsl:value-of select="atom:title"/>
                </title>
                <date>
                    <xsl:call-template name="extract-date">
                        <xsl:with-param name="when" select="substring-before(substring-after(atom:content, 'When: '), '&lt;br /&gt;')" />
                    </xsl:call-template>
                </date>
            </item>
        </xsl:for-each>
    </items>
</xsl:template>

<xsl:template name="extract-date">
    <xsl:param name="when"/>
    <xsl:param name="mmm" select="substring-before(substring-after($when, ' '), ' ')"/>
    <xsl:param name="d" select="substring-before(substring-after(substring-after($when, ' '), ' '), ', ')"/>
    <xsl:param name="y" select="substring-before(substring-after($when, ', '), ' ')"/>
    <xsl:param name="m" select="string-length(substring-before('JanFebMarAprMayJunJulAugSepOctNovDec', $mmm)) div 3 + 1" />
    <xsl:value-of select="concat($m, '/', $d, '/', $y)"/>
</xsl:template>

</xsl:stylesheet>

请注意,发送给命名模板的参数正好是到达前面问题的表达式。

其结果将是:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<items>
   <item>
      <title>Project Manager Meeting</title>
      <date>3/5/2015</date>
   </item>
   <item>
      <title>Analyst Meeting</title>
      <date>2/19/2015</date>
   </item>
</items>

剩下的留给读者做练习。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28775886

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档