XML + XSLT Use Cases

Source: Internet
Author: User
Tags xsl xslt

XML document

<? XML version = "1.0" encoding = "UTF-8"?>
<? XML-stylesheet type = "text/XSL" href = "tool. XSLT"?>
<Tool>
<Field ID = "prodname">
<Value> hammer hg2606 </value>
</Field>
<Field ID = "prodno">
<Value> 32456240 </value>
</Field>
<Field ID = "price">
<Value> $30.00 </value>
</Field>
</Tool>

 

XSLT document

Tool. XSLT

<? XML version = "1.0" encoding = "UTF-8"?>

<XSL: stylesheetversion = "1.0"
Xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">

<XSL: template match = "/">
<HTML>
<Body>
<Form method = "Post" Action = "edittool. aspx">
<H2> tool information (edit): </H2>
<Table border = "0">
<XSL: For-each select = "tool/field">
<Tr>
<TD>
<XSL: value-of select = "@ ID"/>
</TD>
<TD>
<Input type = "text">
<XSL: attribute name = "ID">
<XSL: value-of select = "@ ID"/>
</XSL: attribute>
<XSL: attribute name = "name">
<XSL: value-of select = "@ ID"/>
</XSL: attribute>
<XSL: attribute name = "value">
<XSL: value-of select = "value"/>
</XSL: attribute>
</Input>
</TD>
</Tr>
</XSL: For-each>
</Table>
<Br/>
<Input type = "Submit" id = "btn_sub" name = "btn_sub" value = "Submit"/>
<Input type = "reset" id = "btn_res" name = "btn_res" value = "reset"/>
</Form>

</Body>
</Html>
</XSL: Template>

</XSL: stylesheet>

 

2. tool_updated.xslt

<? XML version = "1.0" encoding = "UTF-8"?>

<XSL: stylesheetversion = "1.0"
Xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">

<XSL: template match = "/">
<HTML>
<Body>
<H2> updated tool information: </H2>
<Table border = "1">
<XSL: For-each select = "tool/field">
<Tr>
<TD>
<XSL: value-of select = "@ ID"/>
</TD>
<TD>
<XSL: value-of select = "value"/>
</TD>
</Tr>
</XSL: For-each>
</Table>
</Body>

</Html>
</XSL: Template>

</XSL: stylesheet>

 

Edittool. aspx

 

Protected void page_load (Object sender, eventargs E)
{

Xmldocument Doc = new xmldocument ();
Doc. Load (server. mappath ("~ /Tool. xml "));

String XSLT = server. mappath ("~ /Tool_updated.xslt ");

LoadFile (Doc, XSLT );
}

Public void LoadFile (xmldocument doc, string XSLT)
{
Extends compiledtransform transform = new extends compiledtransform ();
Transform. Load (XSLT );
Transform. Transform (Doc, null, context. response. output );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.