开发者

Selecting string/literal from a specified child node element using XSLT

开发者 https://www.devze.com 2022-12-22 17:00 出处:网络
this is the excerpt of the XML file. <rdf:RDF> <rdf:Description rdf:about=\"http://abc.org/JohnD\">

this is the excerpt of the XML file.

<rdf:RDF>
        <rdf:Description rdf:about="http://abc.org/JohnD">
            <video:Movie xml:lang="en" xmlns:video="http://example.org/movie">Avatar</video:Movie>
          </rdf:Description>

      <rdf:Description rdf:about="http://abc.org/JohnD">
        <foaf:interest xml:lang="en" xmlns:foaf="http://xmlns.com/foaf/0.1/">games</foaf:interest>
      </rdf:Description>

</rdf:RDF>

the XSL excerpt

<xsl:template match="rdf:RDF/rdf:Description">
   <xsl:value-of select="video:Movie"/>
</xsl:template>

I want to select the literal "Avatar" from the node with the name <video:Movie> only

I ve tried using <xsl:value-of select="video:Movie"/> and various other combinat开发者_JS百科ion, but it just won't display. I have declared the namespace accordingly in the XSL header.


The following code selects the element irrespective of the namespace url:

<xsl:template match="rdf:RDF/rdf:Description">
   <xsl:value-of select="*[name() = 'video:Movie']"/>
</xsl:template>

But if all the namespaces are correct the code you provided should work, I just tested it with the following XSLT (note the video namespace on top of the XSLT).

<xsl:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:video="http://example.org/movie" 
>
    <xsl:output method="html"/>

        <xsl:template match="rdf:RDF/rdf:Description">
            <xsl:apply-templates select="video:Movie"/>
        </xsl:template>
</xsl:stylesheet>
0

精彩评论

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