开发者

What does file:file represent in this XSLT?

I'm starting to use XSLT, and I don't understand this line:

<xsl:apply-templates select="file:file/file:description" />

Why are there 3 files ? I know one of my tags in the XML file is named "file", but why prefixing "file:" ?

Here's the actual code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
   xmlns="http://www.w3.org/1999/xhtml"
   xmlns:file="http://phpdox.de/xml#"
   exclude-result-prefixes="#default file"
   >
   <xsl:output method="html" indent="yes" encoding="utf-8" />

<xsl:template match="/">
    <html>
    <body>
        <xsl:apply-templates select="file:file/file:description" />
    </body>
    </html>
<xsl:template match="file:description">开发者_如何转开发;
    <header>
        <p><xsl:value-of select="@compact" /></p>
        <p><xsl:value-of select="file:description" /></p>
    </header>

</xsl:template>
</xsl:stylesheet>

And the source XML file:

<?xml version="1.0" encoding="UTF-8"?>
<file xmlns="http://phpdox.de/xml#">
  <class>
    <docblock>
      <description compact="foo bar"/>
  [...]


Two of the three file tokens in file:file/file:description are namespace names. In XML and XSLT, a:b means "b in the a namespace". You can see the xmlns line explaining that file is a namespace once you know to look for it.

So the string means to find file:description (which may just look like description if everything in your document is in the file namespace) under file:file. Make sense?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜