[英]XSLT transversing
I am not sure how to go about this problem as I am pretty new to XSLT. 我不知道如何解决这个问题,因为我对XSLT很新。
I am using an xsl:for-each
to loop through the Types
, which is fine but when I am in that loop(Type) how would I select the Rate
using the attribute in the TypeCode
? 我使用
xsl:for-each
循环遍历Types
,这很好但是当我在那个循环(Type)时如何使用TypeCode
的属性选择Rate
? Am I right in thinking the select only has the scope of the for-each that I am in at that time? 我是否正确地认为选择仅具有我当时所处的每个人的范围? There could be many bag elements as well.
也可能有很多包包。
<Bags>
<Bag>
<Types>
<Type TypeCode="DBL">
<Description Name="BLAH">
<Text>BLAH</Text>
<Image/>
</Description>
</Type>
<Type TypeCode="JRS">
<Description Name="BLAH">
<Text>BLAH BLAH</Text>
<Image/>
</Description>
</Type>
</Types>
<Plans>
<Plan PlanCode="DISC" PlanName="Best rate">
<Description Name="Best rate">
<Text>Best available rate</Text>
</Description>
</Plan>
<Plan PlanCode="NOCC" PlanName="No CC Required">
<Description Name="No CC Required">
<Text>Rate- No CC Required</Text>
</Description>
</Plan>
</Plans>
<Rates>
<Rate TypeCode="DBL" PlanCode="DISC">
<Rates>
<Rate>
<Base AmountBeforeTax="0" CurrencyCode="EUR"/>
</Rate>
</Rates>
</Rate>
<Rate TypeCode="JRS" PlanCode="DISC">
<Rates>
<Rate>
<Base AmountBeforeTax="0" CurrencyCode="EUR"/>
</Rate>
</Rates>
</Rate>
</Rates>
</Bag>
</Bags>
Am I right in thinking the select only has the scope of the for-each that I am in at that time?
我是否正确地认为选择仅具有我当时所处的每个人的范围?
Not really , an XPath expression can be relative , in which case it is evaluated off the current node, or absolute (starting with /
) in which case it is evaluated off the current document node. 实际上 ,XPath表达式可以是相对的 ,在这种情况下,它是从当前节点评估的,或绝对的 (以
/
开头),在这种情况下,它将从当前文档节点进行评估。
Even with a relative XPath expression it is possible to select nodes outside of the subtree rooted by the current node -- simply by using reverse axes or the following::
or following-sibling::
axis. 即使使用相对XPath表达式,也可以选择以当前节点为根的子树之外的节点 - 只需使用反向轴或
following::
或following-sibling::
axis即可。
Use : 用途 :
ancestor::Bag/Rates/Rate[@TypeCode = current()/@TypeCode]
This assumes that bags cannot be nested, otherwise a slightly different expression needs to be used: 这假设行李不能嵌套,否则需要使用稍微不同的表达式:
ancestor::Bag[1]/Rates/Rate[@TypeCode = current()/@TypeCode]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.