开发者

XSL: select element value using XPath selector

I've the following XML scheme and I want to select the Table>Row>Field with name = Amount

<?xml version="1.0" encoding="utf-8"?>
<Document>
  <PermitDocument code="01312" id="1">
    <Field name="DocumentType">Certificate</Field>
    ...
    ...
    <Table name="Products">
      <Row>
        <Field name="Amount">1000</Field>
        ...
        ...
      </Row>
      <Row>
        <Field name="Amount">3000</Field>
        ...
        ...
      </Row>
    </Table>
  </PermitDocument>
</Document>

I've开发者_Go百科 the following code for transformation but nothing happens

<xsl:for-each select="Document/PermitDocument/Table[@name='Products']/Row">
    <xsl:value-of select="Field[@name='Amount']" />
    ...
    ...
</xsl:for-each>

C# code

XslTransform xs = new XslTransform();

try
{
  xs.Load("BCIS.xsl");
}
catch (XsltException e)
{
  Console.WriteLine(e.StackTrace);
  Console.ReadLine();
}

xs.Transform("BCIS.xml", "BCIS.html");

What is wrong with the syntax I used to achieve the goal?

Sultan


Input:

<Document>
    <PermitDocument code="01312" id="1">
        <Field name="DocumentType">Certificate</Field>
        <Table name="Products">
            <Row>
                <Field name="Amount">1000</Field>
            </Row>
            <Row>
                <Field name="Amount">3000</Field>
            </Row>
        </Table>
    </PermitDocument>
</Document>

XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <xsl:for-each select="Document/PermitDocument/Table[@name='Products']/Row">
            <xsl:value-of select="Field[@name='Amount']" />
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

Output:

10003000
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜