XML Document Search Application Summary 2

Source: Internet
Author: User
Tags xsl xsl file
This method requests us to look for the data we need in a layer-by-layer manner. if there are many layers, it will be very difficult and easy to make mistakes. Fortunately. NET provides us with another method: SelectSingleNode and SelectNodes. we can directly find this method and request us to find the data we need in one layer. if there are many layers, it will be very difficult to do it, it is also prone to errors. Fortunately,. NET provides us with another method, SelectSingleNode and SelectNodes, so that we can directly find the desired data. For example, if we are looking for a user named "Tim", we can use the following method:

MyDoc. SelectSingleNode ('// member [name = 'Tim']'). ChildNodes. Item (1). InnerText

// Represents any layer of sub-nodes. In this way, we can quickly find what we want. SelectSingleNode is used to find a single node. SelectNodes can find many nodes.

We all know how to find a subnode in XML. how can we find a subnode in a special XML file, the XSL file?

Suppose I have an XSL file like this:

<? Xml version = '1. 0' encoding = 'gb2312 '?>
<Xsl: stylesheet version = '1. 0' xmlns: xsl = 'http: // www.w3.org/5o/#/transform' xmlns: fo = 'http: // www.w3.org/5o/#/format'>
<Xsl: preserve-space elements = 'codes '/>
<Xsl: template match = '/'>
<Xsl: apply-templates/>
</Xsl: template>

<Xsl: template match = 'image'>
<Table align = '{@ location}'>
<Tr>
<Td>

<Xsl: attribute name = 'src'> ../FTP_Magazine/FTP_Issue/
</Img>
</Td>
</Tr>
<Tr>
<Td>
<Center>
<Xsl: apply-templates/>
</Center>
</Td>
</Tr>
</Table>
</Xsl: template>

</Xsl: stylesheet>

We have two variables in asp.net. we need the XSL file to use these two variables in the Transform XML file. What should we do?

The method I used is to first load the XSL file as an XML Document. before applying the file, we found the node to be corrected and corrected it with our variables. At this time, we need to make some changes when searching for this node. the code is as follows:

XmlNamespaceManager nsmanager = new XmlNamespaceManager (registrdoc. NameTable );
Nsmanager. AddNamespace ('xsl ', 'http: // www.w3.org/5o/#/transform ');
Export Doc. SelectSingleNode ('// xsl: attribute [@ name = 'src']', nsmanager). InnerXml = the variable you need to lose

That is to say, ../FTP_Magazine/FTP_Issue/ Before we look for such a node, we need to define an XmlNamespaceManager and use it to find the node we need.


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.