English 中文(简体)
XSLT 转换
原标题:XSLT transversing
  • 时间:2012-05-25 13:21:38
  •  标签:
  • xslt

我不确定该如何解决这个问题,因为我对XSLT相当陌生。

我使用 xsl: for-each 来绕过 Type ,这很好,但当我进入这个循环(Type)时,我如何使用 TypeCode 中的属性选择 Rate ?我是否正确?

<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 , XPath 表达式可以是 relative ,在这种情况下,该表达式从当前节点上评价,或 absolute (从 / 开始),如果该表达式从当前文档节点上评价,则从当前文档节点上评价。

即使使用相对的 XPath 表达式, 也可以在根植于当前节点的子树外选择节点 -- -- 只需使用反向轴或 < code>, 或 < code > 或 < code> 随附的串联轴: 。

<强 > 使用 :

ancestor::Bag/Rates/Rate[@TypeCode = current()/@TypeCode]

这个假设是包包不能筑巢,否则需要使用略有不同的表达方式:

ancestor::Bag[1]/Rates/Rate[@TypeCode = current()/@TypeCode]
问题回答

暂无回答




相关问题
When test hanging in an infinite loop

I m tokenising a string with XSLT 1.0 and trying to prevent empty strings from being recognised as tokens. Here s the entire function, based on XSLT Cookbook: <xsl:template name="tokenize"> ...

quick xslt for-each question

Let s say I have an XML document that has this: <keywords> <keyword>test</keyword> <keyword>test2</keyword> <keyword>test3</keyword> <keyword>test4</...

XSLT Transform XML with Namespaces

I m trying to transform some XML into HTML using XSLT. Problem: I can t get it to work. Can someone tell me what I m doing wrong? XML: <ArrayOfBrokerage xmlns:i="http://www.w3.org/2001/...

XSLT output to HTML

In my XSLT file, I have the following: <input type="button" value= <xsl:value-of select="name">> It s an error as it violates XML rule. What I actually want is having a value from an ...

Mangling IDs and References to IDs in XML

I m trying to compose xml elements into each other, and the problem I am having is when there s the same IDs. Basically what I need to do is mangle all the IDs in an xml file, as well as the ...

Sharepoint 2007 Data view Webpart custom parameters

I m sort of new to the custom parameters that can be setup on a DataView Webpart. There are 6 options: - None - Control - Cookie - Form - QueryString - Server Variable I think that None, Cookie and ...

热门标签