저는 XSLT에서 초보자이며 XML을 XML로 변환하는 데 사용합니다.최저 가격을 찾으려면 XSLT
나는 합계가 가장 낮은 Prices
태그를 얻어야합니다.
소스 XML :
<Result>
<Fares>
<Fare>
<Prices>
<Price type="adt" ticket="15"/>
<Price type="chd" ticket="10"/>
<Price type="inf" ticket="10"/>
<Prices>
</Fare>
<Fare>
<Prices>
<Price type="adt" ticket="10"/>
<Price type="chd" ticket="10"/>
<Price type="inf" ticket="10"/>
<Prices>
</Fare>
<Fare>
<Prices>
<Price type="adt" ticket="5"/>
<Price type="chd" ticket="5"/>
<Price type="inf" ticket="5"/>
<Prices>
</Fare>
<Fare>
<Prices>
<Price type="adt" ticket="10"/>
<Price type="chd" ticket="5"/>
<Price type="inf" ticket="5"/>
<Prices>
</Fare>
</Fares>
</Result>
XSLT :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="Result">
<xsl:element name="Lowest">
<xsl:variable name="lowest" select="Fares/Fare/Prices[not(sum(Price/@ticket) > //Fares/Fare/Prices[sum(Price/@ticket)])]"/>
<xsl:copy-of select="$lowest"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
출력 :
<Lowest>
<Prices>
<Price type="adt" ticket="15"/>
<Price type="chd" ticket="10"/>
<Price type="inf" ticket="10"/>
<Prices/>
</Prices>
</Lowest>
전 pected 출력 :
<Lowest>
<Prices Total="15">
<Price type="adt" ticket="5"/>
<Price type="chd" ticket="5"/>
<Price type="inf" ticket="5"/>
<Prices>
</Lowest>
출력 위와 같이 또한 속성으로서 가장 낮은 값을 가진 Prices
태그를 가져야한다.
도와주세요.
안녕, 당신은 당신의 XSLT 코드를 공유 할 수를 ..? 너 뭐 해봤 니? –
표시하고있는 XSLT가 실제로 말하는 출력을 제공합니까? 나를 위해 Saxon 6.5.5를 사용하면 다른 출력을 얻을 수 있습니다. 네 개의 ''요소와 자손을 모두 출력합니다. –
LarsH
@LarsH - XML을 XML로 변환하기 위해 java를 사용하고 있으며 엔진은 JAXP (기본값)입니다. –