2009-07-14 12 views
0

は私が「」インフォボックス科学研究テンプレート」を含むフランスのページを見つけるためにwikipedia APIを使用したいです。だから、私のアイデアはXPROCと、次の文書を処理することでした:Recusive変換:「英語版で行方不明:文書()とmediawikiの

http://fr.wikipedia.org/w/api.php?action=query&format=xml&list=embeddedin&eititle=Template:Infobox%20Scientifique&eilimit=400

と、次のXSLTスタイルシート:

<?xml version='1.0' ?> 
<xsl:stylesheet 
    xmlns:xsl='http://www.w3.org/1999/XSL/Transform' 
    version='1.0' 
    > 
<xsl:output method='text' indent="yes"/> 
<xsl:template match="/"> 
<xsl:apply-templates select="api"/> 
</xsl:template> 

<xsl:template match="api"> 
<xsl:for-each select="query/embeddedin/ei"> 
<xsl:variable name="title" select="translate(@title,&apos; &apos;,&apos;_&apos;)"/> 
<xsl:variable name="english-title"> 
<xsl:call-template name="englishTitle"><xsl:with-param name="title" select="@title"/></xsl:call-template> 
</xsl:variable> 

<xsl:value-of select="$english-title"/><xsl:text> 
</xsl:text> 

</xsl:for-each> 
</xsl:template> 

<xsl:template name="englishTitle"> 
<xsl:param name="title"/> 
<xsl:variable name="uri1" select="concat(&apos;http://fr.wikipedia.org/w/api.php?action=query&amp;format=xml&amp;prop=langlinks&amp;lllimit=500&amp;titles=&apos;,translate($title,&apos; &apos;,&apos;_&apos;))"/> 
<xsl:message><xsl:value-of select="$uri1"/></xsl:message> 
<xsl:message>count=<xsl:value-of select="count(document($uri1,/api/query/pages/page/langlinks/ll))"/></xsl:message> 
</xsl:template> 

</xsl:stylesheet> 

XSLTテンプレートを含むすべての記事を抽出し、私が欲しかった各記事のためにウィキペディアに電話してウィキ間のリンクを得る。テンプレートenglishTitleは、xpath関数)を呼び出します。

しかし、それは常にcount(ll)=1と言われていますが、たくさんのノードがあります。 (例えば、http://fr.wikipedia.org/w/api.php?action=query&format=xml&prop=langlinks&lllimit=500&titles=Carl_Sagan)。

文書()によって返されるノードを処理できませんか?

答えて

1

あなたは試してみてください:

<xsl:value-of select="count(document($uri1)/api/query/pages/page/langlinks/ll)"/> 

を別のノートには -

translate(@title,&apos; &apos;,&apos;_&apos;) 

を意味することになって何ですか?何が間違っている:

translate(@title, ' ', '_') 

あなたは属性値を区切る引用符の種類を使用する場合を除き、XML属性で単一引用符をエンコードする必要はありません。これらのすべてが有効です。

name="foo&quot;'foo" 
name='foo&apos;"foo' 

はあなたの全体の変換は次のようなものにすることができる。

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

    <xsl:param name="baseUrl" select="'http://fr.wikipedia.org/w/api.php?action=query&amp;format=xml&amp;prop=langlinks&amp;lllimit=500&amp;titles='" /> 

    <xsl:template match="ei"> 
    <xsl:variable name="uri" select="concat($baseUrl ,translate(@title,' ','_'))"/> 
    <xsl:variable name="doc" select="document($uri)"/> 

    <xsl:value-of select="$uri"/> 
    <xsl:text>&#10;</xsl:text> 

    <xsl:text>count=</xsl:text> 
    <xsl:value-of select="count($doc/api/query/pages/page/langlinks/ll)"/> 
    <xsl:text>&#10;</xsl:text> 
    </xsl:template> 

    <xsl:template match="text()" /> 
</xsl:stylesheet> 

は、XSLTのデフォルトテンプレートは、あなたのために働くしましょう - 彼らは、バックグラウンドで再帰のすべての操作を行い、処理したいノードをキャッチするだけで済みます(デフォルトのtext()テンプレートを空の文字列で上書きして不要なテキストの出力を防止するだけです)。

+0

ありがとう、それは働いた:-) – Pierre

関連する問題