我需要执行xslt转换作为块,我有一个输入请求,其中包含多个建筑物内部建筑物标签,对于每个10建筑物,我需要创建一个Valuations标签,设置一些常量值并将10个建筑物值映射到该位置/地址标签Street,Line1和country。 即,如果我发送21建筑物,我需要创建Valuations标签并为每个拆分10,10和1建筑物转换xml。同样,如果我发送35建筑物,我需要为每个拆分10,10,10和5创建Valuations标签分别变换。 此外,我想将参数10外部化,我将其用作块decider.ie。,如果我将参数更改为5并发送21个建筑物,则应为每个5,5,5,5和1建筑物创建5个Valuations标记,将建筑物映射到locaton值。
请告诉我如何在xslt中实现它。
我在我的应用程序中有限制我只能使用xslt 1.0
输入XML:
<buildings>
<building>
<street>Stewart Place</street>
<addressline-1>27 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>28 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>29 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>40 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>41 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>42 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>43 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>44 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>45 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>46 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>47 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>48 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>49 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>40 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>41 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>42 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>43 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>44 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>45 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>46 Stewart Place</addressline-1>
<country>US</country>
</building>
<building>
<street>Stewart Place</street>
<addressline-1>47 Stewart Place</addressline-1>
<country>US</country>
</building>
</buildings>
XSLT:
<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:param name="SplitNo" select="10"/>
<xsl:template match="/*">
<provider-request>
<xsl:apply-templates select="building[position() mod $SplitNo = 1]"/>
</provider-request>
</xsl:template>
<xsl:template match="building">
<Valuations>
<request>
<CompanyID>94A7DB70-F90F-4EE7-A614-E548D1045277</CompanyID>
<Logon>ydahmouni</Logon>
<CalculateValuation>true</CalculateValuation>
<ReturnAddedValuation>true</ReturnAddedValuation>
<Valuation>
<Locations>
<xsl:for-each select=".|following-sibling::building[not(position() > $SplitNo -1)]">
<location>
<Address>
<Street><xsl:value-of select="street" /></Street>
<Line1><xsl:value-of select="addressline-1" /></Line1>
<country><xsl:value-of select="country" /></country>
</Address>
</location>
</xsl:for-each>
</Locations>
</Valuation>
</request>
</Valuations>
</xsl:template>
</xsl:stylesheet>
预期产出:
<provider-request>
<Valuations>
<request>
<CompanyID>94A7DB70-F90F-4EE7-A614-E548D1045277</CompanyID>
<Logon>ydahmouni</Logon>
<CalculateValuation>true</CalculateValuation>
<ReturnAddedValuation>true</ReturnAddedValuation>
<Valuation>
<Locations>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>27 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>28 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>29 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>40 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>41 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>42 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>43 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>44 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>45 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>46 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
</Locations>
</Valuation>
</request>
</Valuations>
<Valuations>
<request>
<CompanyID>94A7DB70-F90F-4EE7-A614-E548D1045277</CompanyID>
<Logon>ydahmouni</Logon>
<CalculateValuation>true</CalculateValuation>
<ReturnAddedValuation>true</ReturnAddedValuation>
<Valuation>
<Locations>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>47 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>48 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>49 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>40 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>41 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>42 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>43 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>44 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>45 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>46 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
</Locations>
</Valuation>
</request>
</Valuations>
<Valuations>
<request>
<CompanyID>94A7DB70-F90F-4EE7-A614-E548D1045277</CompanyID>
<Logon>ydahmouni</Logon>
<CalculateValuation>true</CalculateValuation>
<ReturnAddedValuation>true</ReturnAddedValuation>
<Valuation>
<Locations>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>47 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
</Locations>
</Valuation>
</request>
</Valuations>
</provider-request>
实际输出:
<provider-request>
<Valuations>
<request>
<CompanyID>94A7DB70-F90F-4EE7-A614-E548D1045277</CompanyID>
<Logon>ydahmouni</Logon>
<CalculateValuation>true</CalculateValuation>
<ReturnAddedValuation>true</ReturnAddedValuation>
<Valuation>
<Locations>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>27 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>28 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>29 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>40 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>41 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>42 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>43 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>44 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>45 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>46 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
</Locations>
</Valuation>
</request>
</Valuations>
<Valuations>
<request>
<CompanyID>94A7DB70-F90F-4EE7-A614-E548D1045277</CompanyID>
<Logon>ydahmouni</Logon>
<CalculateValuation>true</CalculateValuation>
<ReturnAddedValuation>true</ReturnAddedValuation>
<Valuation>
<Locations>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>47 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>48 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>49 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>40 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>41 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>42 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>43 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>44 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>45 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>46 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
</Locations>
</Valuation>
</request>
</Valuations>
<Valuations>
<request>
<CompanyID>94A7DB70-F90F-4EE7-A614-E548D1045277</CompanyID>
<Logon>ydahmouni</Logon>
<CalculateValuation>true</CalculateValuation>
<ReturnAddedValuation>true</ReturnAddedValuation>
<Valuation>
<Locations>
<location>
<Address>
<Street>Stewart Place</Street>
<Line1>47 Stewart Place</Line1>
<country>US</country>
</Address>
</location>
</Locations>
</Valuation>
</request>
</Valuations>
</provider-request>