With the help of absolute path and relative path my question is how i will get into testing element then i have to select import element from there.
実際には、への完全なパスを指定して、子testing
があることを確認する必要はありません。import
XSLT処理モデル(組み込みテンプレート)は、テンプレートおよび適切なテンプレート一致パターンと組み合わせて、ナビゲーションを行います。
特定のノードに一致する明示的なテンプレートがない場合、組み込みのテンプレートが実行用に選択されます。組み込みテンプレートを適用した累積的な結果は、ドキュメントツリーがトラバースされ、テキストノードのみが出力されることです。
別の特定の方法で処理する必要があるノードに対してのみ、組み込みのテンプレートをオーバーライドするテンプレートを指定できます。組み込みテンプレートがノードの子にテンプレートを適用し、そのノードに一致する明示的な(ユーザー提供の)テンプレートがある場合、この明示的なテンプレートがそのノードの実行/処理用に選択されます。
この短いXSLT1.0変換:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<maindocument>
<xsl:apply-templates/>
</maindocument>
</xsl:template>
<xsl:template match="import/downloading">
<import>
<doctype><xsl:value-of select="substring-before(., ' ')"/></doctype>
<docint><xsl:value-of select="substring-after(., ' ')"/></docint>
</import>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
提供されたXMLドキュメントに適用した場合:
<maindocument>
<first>
<testing>random text</testing>
<checking>random test</checking>
</first>
<testing>
<testing>sample</testing>
<checking>welcome</checking>
<import>
<downloading>valuable text</downloading>
</import>
</testing>
</maindocument>
必要な正しい結果を生成します:
<maindocument>
<import>
<doctype>valuable</doctype>
<docint>text</docint>
</import>
</maindocument>