私は XSLT の学習を混乱させており、Web サービスから一度に 20 個しか取得できない 100 個を超える製品を最終的にフィルター処理して並べ替える必要があるという課題があります。私はそれらの製品をうまく取り出して操作することができましたが、それらが 1 つのリストであるかのようにではなく、元のバッチでのみでした. そこで、次のように個別のファイルを1つに変換しようとしました。
次のように複数のファイルを結合します。
A.xml
<?xml version="1.0" encoding="UTF-8"?>
<productSearchResponse>
<products>
<product>
<code>A1</code>
<item> SAUVIGNON RESERVA</item>
<country>Spain</country>
<region>Penedes</region>
<category>Red</category>
<style>Full-bodied</style>
</product>
<product>
<code>A2</code>
<item>RESERVE RIESLING</item>
<country>France</country>
<region>Alsace</region>
<category>White</category>
<style>Aromatic</style>
</product>
<product>
<code>A3</code>
<item>GAMAY</item>
<country>Canada</country>
<region>Ontario</region>
<category>Red</category>
<style>Medium-bodied</style>
</product>
</products>
</productSearchResponse>
...これで:
B.xml
<?xml version="1.0" encoding="UTF-8"?>
<productSearchResponse>
<products>
<product>
<code>B1</code>
<item>BOURGOGNE CHARDONNAY</item>
<country>France</country>
<region>Burgundy</region>
<category>White</category>
<style>Light</style>
</product>
<product>
<code>B2</code>
<item>ONTARIO RIESLING II</item>
<country>Canada</country>
<region>Ontario</region>
<category>White</category>
<style>Off-dry</style>
</product>
<product>
<code>B3</code>
<item>WEST COAST CAB SAUV</item>
<country>USA</country>
<region>California</region>
<category>Red</category>
<style>Full-bodied</style>
</product>
</products>
</productSearchResponse>
...次のような新しい xml ファイルを取得するには: all.xml
<?xml version="1.0" encoding="UTF-8"?>
<productSearchResponse>
<products>
<product>
<code>A1</code>
<item> SAUVIGNON RESERVA</item>
<country>Spain</country>
<region>Penedes</region>
<category>Red</category>
<style>Full-bodied</style>
</product>
<product>
<code>A2</code>
<item>RESERVE RIESLING</item>
<country>France</country>
<region>Alsace</region>
<category>White</category>
<style>Aromatic</style>
</product>
<product>
<code>A3</code>
<item>GAMAY</item>
<country>Canada</country>
<region>Ontario</region>
<category>Red</category>
<style>Medium-bodied</style>
</product>
<product>
<code>B1</code>
<item>BOURGOGNE CHARDONNAY</item>
<country>France</country>
<region>Burgundy</region>
<category>White</category>
<style>Light</style>
</product>
<product>
<code>B2</code>
<item>ONTARIO RIESLING II</item>
<country>Canada</country>
<region>Ontario</region>
<category>White</category>
<style>Off-dry</style>
</product>
<product>
<code>B3</code>
<item>WEST COAST CAB SAUV</item>
<country>USA</country>
<region>California</region>
<category>Red</category>
<style>Full-bodied</style>
</product>
</products>
</productSearchResponse>
私はこれを使ってみました
ABC.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="ABC.xsl"?>
<essentials>
<webservice filename="A.xml"/>
<webservice filename="B.xml"/>
<!-- etc -->
</essentials>
これとともに
ABC.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" indent="yes"/>
<xsl:template match="/">
<output>
<xsl:for-each select="/essentials/webservice">
<xsl:for-each select="document(@filename)/productSearchResponse/products/product">
<product>
<code>
<xsl:value-of select="code"/>
</code>
<item>
<xsl:value-of select="item"/>
</item>
<country>
<xsl:value-of select="country"/>
</country>
<region>
<xsl:value-of select="region"/>
</region>
<category>
<xsl:value-of select="category"/>
</category>
<style>
<xsl:value-of select="style"/>
</style>
</product>
</xsl:for-each>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>
....しかし、ブラウザでこれで終わります:
A1 SAUVIGNON RESERVASpainPenedesRedFull-bodiedA2RESERVE RIESLINGFranceAlsaceWhiteAromaticA3GAMAYCanadaOntarioRedMedium-bodiedB1BOURGOGNE CHARDONNAYFranceBurgundyWhiteLightB2ONTARIO RIESLING IICanadaOntarioWhiteOff-dryB3WEST COAST CAB SAUVUSACaliforniaRedFull-bodiedC1BURGUNDY PINOT NOIRFranceBurgundyRedMedium-bodiedC2CALIFORNIAN WHITEUSACaliforniaWhiteOff-dryC3CANADIAN REDCanadaOntarioRedFull-bodied
Firebug は、舞台裏で結果が目的の xml であることを示しています。私が困惑しているところは次のとおりです:結果を使用できるフォームに変換するにはどうすればよいですか?それを通常のxmlとして扱い、さらに変換を行うことができますか? そして、私は正しいアプローチを見つけましたか、それとも間違ったツリーを吠えていて、これを複雑にしすぎていますか?