开发者

how to get value to line item from header

I have this xml:

<Documents>
    <Header Document_No="Numb1" Warehouse="WH2">
        <Body Position="1" Quantity="11" />
        <Body Position="2" Quantity="10" />
    </Header>
    <Header Document_No="Numb2" Warehouse="WH1">
        <Body Position="1" Quantity="20"/>
        <Body Position="2" Quantity="13"/>
        <Body Position="3" Quantity="12"/>
    </Header>
</Documents>

My xslt:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output encoding="utf-8" indent="yes" method="xml"/>
    <xsl:template match="/">
        <GroupDocuments>
            <xsl:apply-templates/>
        </GroupDocuments>
    </xsl:template>
    <xsl:template match="Header">
        <Message>
            <Document>
                <Document-Header>
                    <DocNumber>
                        <xsl:value-of select="@Document_No"/>
                    </DocNumber>
                </Document-Header>
                <Lines>
                    <xsl:apply-templates select="Body"/>
                </Lines>
            </Document>
        </Message>
    </xsl:template>
    <xsl:template match="Body">
        <Line>
            <Line-Item>
                <LineNumber>
                    <xsl:value-of select="@Position"/>
                </LineNumber>
                <Quantity>
                    <xsl:value-of select="@Quantity"/>
                </Quantity>
            </Line-Item>
            <Line-Warehouse>
                <Warehouse>
                    <--Where is a problem-->>
                    <xsl:value-of select=""/>
                </Warehouse>
            </Line-Warehouse>
        </Line>
    </xsl:template>

</xsl:stylesheet>

I'm stuck to getting value of warehouse in Line-Warehouse tags, 开发者_JS百科how to take value of warehouse from header when I proceesing Body? Please help to solve it.

result should be:

<?xml version="1.0" encoding="utf-8"?>
<GroupDocuments xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <Message>
        <Document>
            <Document-Header>
                <DocNumber>Numb1</DocNumber>
            </Document-Header>
            <Lines>
                ..............................................
                ............................................
                <Line>
                    <Line-Item>
                        <LineNumber>2</LineNumber>
                        <Quantity>10</Quantity>
                    </Line-Item>
                    <Line-Warehouse>
                        <Warehouse>WH2</Warehouse>
                    </Line-Warehouse>
                </Line>
            </Lines>
        </Document>
    </Message>
    <Message>
        <Document>
            <Document-Header>
                <DocNumber>Numb2</DocNumber>
            </Document-Header>
            <Lines>
                <Line>
                    <Line-Item>
                        <LineNumber>1</LineNumber>
                        <Quantity>20</Quantity>
                    </Line-Item>
                    <Line-Warehouse>
                        <Warehouse>WH1</Warehouse>
                    </Line-Warehouse>
                </Line>
.....................................
.....................................
            </Lines>
        </Document>
    </Message>
</GroupDocuments>


In the mentioned template the current node is body node. You want select the attribute of its parent.

Use this simple XPath:

"../@Warehouse"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜