私はXSLの初心者です。 HTMLから2つの値(タイトルと説明)を抽出したいと思います。私は他のすべてのタイトルと説明の下を持ってXSLを使用してHTMLからタイトルと説明のようなメタデータを抽出する方法
/html/body/div[2]/div[4]/div[4]/table/tbody/
:私のHTMLは、例えばのために
...
tbody id="_tableBody">
<tr id="tcm:526-94999" class="alt-rowcolor" style="display: table-row;">
<th class="heading" scope="row" style="display: table-cell;">
<a onclick="displayAgreementPDFPopIn('202', 'ddctable-526-93813', 'Link_1382596320857', '540', 'false')" href="javascript:void(0)">529 Plan – Investment Instructions</a>
</th>
<td class="description" style="display: table-cell;">Change how your future contributions are invested or make an exchange of the contributions and earnings currently invested in your 529 college savings plan.</td>
</tr>
...
どのように見えるかこれは、私はこれは要素のXPATHがある
<title> 529 Plan – Investment Instructions</title>
<description> Change how your future contributions are invested or make an exchange of the contributions and earnings currently invested in your 529 college savings plan </description>
たいですこのパス。私はこの変換のために以下のXSLを作成しました。
<xsl:template match="/">
<xsl:apply-templates select="/html/body/div[2]/div[4]/div[4]/table/tbody" />
</xsl:template>
<xsl:template match="tbody">
<xsl:call-template name="PDF_metadata">
</xsl:call-template>
</xsl:template>
<xsl:template name="PDF_metadata">
<xsl:variable name="title" select="/tr/th/a">
<xsl:variable name="description" select="/tr/th/td"/>
<xsl:attribute name="title">
<xsl:value-of select="$title" />
</xsl:attribute>
<xsl:attribute name="description">
<xsl:value-of select="$description" />
</xsl:template>
これはXSLを使用する正しい方法ですか?私はこの権利をしていますか?どんな助けもありがとう。
ありがとうございました。私は多くのtrとtdタグを持つ大きなhtmlファイルを持っています。私はその要素に到達するには、このパス全体/ html/body/div [2]/div [4]/div [4]/table/tbody /を指定する必要があると思います。どう思いますか? – Rose
@NupurJaiswalが更新されました。あなたの 'tbody'タグは' id'属性を持っているので、 '/ html/body/div [2]/div [4]/div [4]/table/tbody'から ' // tbody [@id = '_ tableBody'] ' – AJNeufeld
素晴らしい。どうもありがとう。私はこの答えをチェックします – Rose