2016-12-05 51 views
1

我怎么能请把以下(大写字母标签,即<RSS>和大写字母,即属性TYPE="audio/mpeg"小写所有的标签名称,并使用XSLT

<RSS xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"> 
    <CHANNEL> 
     <title>Example Title</title> 
     <LINK>Example Link</link> 
     <atom:link HREF="http://example.com/feed" REL="self" TYPE="application/rss+xml"/> 
     <itunes:subtitle>Example subtitle with itunes namespace</itunes:subtitle> 
     <itunes:owner> 
      <itunes:name>OWNER NAME</itunes:name> 
      <itunes:email>[email protected]</itunes:email> 
     </itunes:owner> 
     <ITEM> 
      <TITLE>Title Name here</TITLE> 
      <itunes:author>Author name here</itunes:author> 
      <ENCLOSURE TYPE="audio/mpeg" URL="http://www.podtrac.com/abc.mp3" LENGTH="31805"/> 
     </ITEM> 
    </CHANNEL> 
</RSS> 

进入这个(小写字母标签,即<rss> RSS XML中的属性和小写字母属性,即type="audio/mpeg"

<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"> 
    <channel> 
     <title>Example Title</title> 
     <link>Example Link</link> 
     <atom:link href="http://example.com/feed" rel="self" type="application/rss+xml"/> 
     <itunes:subtitle>Example subtitle with itunes namespace</itunes:subtitle> 
     <itunes:owner> 
      <itunes:name>OWNER NAME</itunes:name> 
      <itunes:email>[email protected]</itunes:email> 
     </itunes:owner> 
     <item> 
      <title>Title Name here</title> 
      <itunes:author>Author name here</itunes:author> 
      <enclosure TYPE="audio/mpeg" url="http://www.podtrac.com/abc.mp3" length="31805"/> 
     </item> 
    </channel> 
</rss> 

使用XSLT?

注:

  1. 需要在所有的标签和被小写的<RSS>不只是我举的例子的人来<rss>所有属性,并TYPE="audio/mpeg"type="audio/mpeg"
  2. 我将使用PHP来运行这
  3. 请注意在<rss>标签内的xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"行的一个名称空间设置 - 这必须保持
  4. 请注意iTunes的命名空间的项目,如<itunes:name>OWNER NAME</itunes:name> - 这些必须保持完全一致
+0

退房http://stackoverflow.com/questions/586231/how-can-i-convert-a-string-to-upper-or-lower-case-with-xslt – Meyer

+0

@SMeyer不幸的是,这不起作用。它删除了命名空间,所以在我的问题结束时我的列表中的数字2和3失败了。 – mrmrw

+0

链接主要是为了降低功能。我建议你在这里发布XSLT代码的最小可执行版本,以便更容易地看到发生了什么问题。请记住,stackoverflow不是一个代码写入服务。 – Meyer

回答

2

这给出了XSLT的1.0期望的结果:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"> 
    <xsl:output indent="yes" /> 
    <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" /> 
    <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" /> 

    <!-- lowercase'es all elements names and copies namespaces--> 
    <xsl:template match="*"> 
     <xsl:variable name="rawName" select="substring-before(name(), ':')"/> 
     <xsl:element name="{translate(name(), $uppercase, $smallcase)}" namespace="{namespace-uri()}"> 
      <xsl:copy-of select="namespace::*"/> 
      <xsl:apply-templates select="node()|@*"/> 
     </xsl:element> 
    </xsl:template> 

    <!-- lowercase'es all attribute names --> 
    <xsl:template match="@*"> 
     <xsl:attribute name="{translate(name(), $uppercase, $smallcase)}"> 
      <xsl:value-of select="." /> 
     </xsl:attribute> 
    </xsl:template> 

    <!-- copies the rest --> 
    <xsl:template match="text() | comment() | processing-instruction()"> 
     <xsl:copy/> 
    </xsl:template> 

</xsl:stylesheet> 
+0

绝对不可思议。优雅,完美。你是个天才!非常非常感谢你。我会以最好的方式回报你 - 通过在StackOverflow上回答大量其他人的问题来传播爱。再次感谢你! – mrmrw

+0

也是关键行“”?那是我失踪的吗? – mrmrw

+0

我真的非常感激这:) :) – mrmrw

相关问题