0

API を介して、org.w3c.dom と XPath を介して解析しようとしている XML ファイルを取得します。XML ファイルの一部には、HTML コンテンツが記述されています。

<Para>Since 2001, state and local health departments in the US have accelerated efforts to prepare for bioterrorism and other high-impact public health emergencies. These activities have been spurred by federal funding and guidance from the US Centers for Disease Control and Prevention (CDC) and the Health Resources and Services Administration (HRSA) 
     <CitationRef CitationID="B1">1</CitationRef>  
     <CitationRef CitationID="B2">2</CitationRef> . Over time, the emphasis of this guidance has expanded from bioterrorism to include "terrorism and non-terrorism events, including infectious disease, environmental and occupational related emergencies" 
     <CitationRef CitationID="B4">4</CitationRef> as well as pandemic influenza.
</Para>

これは次のようになります。

<p>Since 2001, state and local health departments in the US have accelerated efforts to prepare for bioterrorism and other high-impact public health emergencies. These activities have been spurred by federal funding and guidance from the US Centers for Disease Control and Prevention (CDC) and the Health Resources and Services Administration (HRSA) 
     <a href="link/B1">1</a>  
     <a href="link/B2">3</a> . Over time, the emphasis of this guidance has expanded from bioterrorism to include "terrorism and non-terrorism events, including infectious disease, environmental and occupational related emergencies" 
     <a href="link/B4">4</a> as well as pandemic influenza.
</p>

これを達成する方法について何か提案はありますか? 主な問題は、タグを取得し、その場所を維持しながらタグを置き換えることです。

4

1 に答える 1

1

XSLT を使用してこれを行う方法は次のとおりです。

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="Para">
  <p>
    <xsl:apply-templates select="@* | node()"/>
  </p>
</xsl:template>

<xsl:template match="CitationRef[@CitationID]">
  <a href="link/{@CitationID}">
    <xsl:apply-templates/>
  </a>
</xsl:template>

</xsl:stylesheet>
于 2012-04-13T10:05:52.300 に答える