IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  XML  >

Thinking XML: Basic XML and RDF techniques for knowledge management

Part 2: Combining files into an RDF model, and basic RDF querying

developerWorks

Return to article


Listing 2: XSLT transform to convert XML issue documents to RDF in batch mode
        
  <?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:it="http://xmlns.rdfinference.org/ril/issue-tracker"
  xmlns:rit="http://xmlns.rdfinference.org/ril/issue-tracker#"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:dc="http://purl.org/metadata/dublin_core#"
  version="1.0"
>
  <xsl:output indent="yes"/>
  <xsl:param name="it-base" select="'http://meta.rdfinference.org/ril/issue-tracker/'"/>
  <xsl:param name="it-schema" select="'http://schema.rdfinference.org/ril/issue-tracker#'"/>
  <xsl:param name="it-users" select="'http://users.rdfinference.org/ril/issue-tracker#'"/>
  <xsl:template match="/">
    <rdf:RDF>
      <xsl:apply-templates/>
    </rdf:RDF>
  </xsl:template>
  <xsl:template match="issue">
    <xsl:apply-templates select="document(.)/*"/>
  </xsl:template>
  <xsl:template match="it:issue">
    <xsl:call-template name="handle-issue"/>
  </xsl:template>
  <xsl:template name="handle-issue">
    <xsl:apply-templates select="it:reference" mode="resolve-ref"/>
    <rdf:Description ID="{@id}">
      <xsl:apply-templates/>
    </rdf:Description>
  </xsl:template>
  <xsl:template match="it:author">
    <xsl:element name="it:author" namespace="{$it-schema}">
      <xsl:choose>
        <xsl:when test="@userid='yes'">
          <xsl:attribute name="rdf:resource">
            <xsl:value-of select="concat($it-users, @tag)"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@tag"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:element>
  </xsl:template>
  <xsl:template match="it:action">
    <rit:action>
      <rdf:Description>
        <rit:assign-to rdf:resource="{concat($it-users, it:assign/@to)}"/>
        <rit:body><xsl:value-of select="it:description"/></rit:body>
      </rdf:Description>
    </rit:action>
  </xsl:template>
  <xsl:template match="it:comment">
    <rit:comment>
      <rdf:Description>
        <xsl:apply-templates/>
      </rdf:Description>
    </rit:comment>
  </xsl:template>
  <xsl:template match="it:comment/concur">
    <rit:body>I agree</rit:body>
  </xsl:template>
  <xsl:template match="it:comment/it:body">
    <rit:body><xsl:value-of select="."/></rit:body>
  </xsl:template>
  <xsl:template match="it:reference" mode="resolve-ref">
    <xsl:choose>
      <xsl:when test="it:spec">
        <rdf:Description about="{concat($it-base,it:spec/@id)}">
          <rit:issue rdf:resource="#{../@id}"/>
        </rdf:Description>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="it:reference"/>
  <xsl:template match="it:main"/>
  <xsl:template match="it:body"/>
  <xsl:template match="it:description"/>
</xsl:stylesheet>
      

Return to article

    关于 IBM 隐私条约 联系 IBM 使用条款