Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert XML data into HTM

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to convert XML data into HTM". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

You can convert XML data to HTML using a simple XSL stylesheet. As the XML specification evolves, it seems necessary to meet everyone's needs in the new version; suppose you have XML data that represents the content of a page, and now you want to convert its content into a layout. Here is the XML you want to convert:

Folder1

File1

String

fifty

Somedata

This content represents a set of folders, files, and domains. Each folder contains files, and each file contains fields for entering data. Each folder in the folder group will appear as a TR element and a TD element on the first line of a TABLE. Each file in the filegroup is represented as a TR element and a TD element in the first line of a TABLE element nested in the folder TR element. Each domain in the domain group will be represented as an INPUT in the associated file.

Here is the XSL for this transformation:

FunctiongetElementCount (nodelist,what) {

Varrtrn=0

Rtrn=nodelist [0] [xss_clean] .selectNodes (what) .length

Return (rtrn 1); / / 1isaddedforfillerTD

}

Width:55px

Width:55px

Text

In the stylesheet tag, several namespaces are set, including the xsl namespace that defines all xsl transformation tags. Allows us to create msxml namespaces of user functions that can be used in stylesheets. Use it to get all the child elements in order to get a set of COLSPAN attributes of a TD tag. A fn namespace used to join a set of user-defined functions, which is created by msxml:script element.

Then, we create an external TABLE and the first TR. In TR, create a TD for each folder specified in XML. The xsl:element tag is used because it allows you to add a custom attribute or execute a function to set an attribute for the COLSPAN attribute in another TD element.

After you have created the required TD for each folder, start creating the TR for each folder. Add only one TD to this TR, but set its COLSPAN property to equal the number of folder tags in the folder group plus one. The extra one is used to fill in blanks in a fixed layout style TABLE.

To get the COLSPAN, pass in the current context (here by "." Specify) and the name of the calculated node. In the function, get the number of nodes specified in the current context, paraentNode, and XPath query. The function then returns this number plus one to populate the TD.

With this TD, embed another TABLE in it, and the TABLE contains each file in the filegroup. From this point on, the process is the same as an external TABLE transformation. The final step is to add the fields in each file.

Once the generic layout is complete, you can start to add user interface features, such as hiding other folders and file lines, until the user clicks the relevant tab. This can be achieved by writing a script that supports this function, adding an onclick xsl:attribute element to the folder and file TD element, and then setting its value to the name of the script function.

Finally, after the general function is complete, you can add class xsl:attributes and add the relevant classNames to STYLE or CSS to get the look you want.

This example creates a foundation for the File-Folder-Field view used in deploying Web data solutions.

This is the end of "how to convert XML data into HTM". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report