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 use XSL to translate Web service applications

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you "how to use XSL to translate Web service applications", the content is easy to understand, clear, hope to help you solve your doubts, let the editor lead you to study and learn "how to use XSL to translate Web service applications" this article.

A common problem with Web service applications is that real back-end software does not support xml (or at least does not support the standardized XML used by your Web services). To solve this problem, many architectures implement a translation phase to interpret the received XML and convert it into a more appropriate format that the back-end system can recognize. Although there are many ways to translate XML into different formats, Extensible stylesheet language (eXtensibleStylesheet Language,XSL) provides a robust, standard, and XML-friendly solution.

Some common problems

There are many places that may need to be translated between the XML message and the application that will process it. However, there are many common problems, including:

Query (Lookup)

Mapping (Mapping)

Aggregation (Aggregation)

Split (Splitting)

Formula (Formulas)

Reorder (Reordering)

The query processing accepts the received value and maps it to a different value for the target system. For example, your XML has a value of 309, but the value required by the application is "Uber Widget".

Mapping is essentially about reassigning a value from one field to another. For example, in XML, you might have an AccountNumber element that needs to be reassigned as a new element called CustomerAccountNumber.

The aggregation process combines two or more projects from XML into a single project for back-end systems. A common example is the combination of last name and first name fields into a single name (field). Segmentation is the reverse operation of aggregation, which divides a value of XML into two or more separate components.

Formula processing generally involves calculating one or more XML values to get a value for a new application. One example is to use XML sub-orders to calculate the total amount of orders.

Finally, reordering is the process of changing the sequence or structure of items in the XML so that they can match the sequence or structure expected by the target system.

Mapping example

Now let's take a closer look at the process with an example. Let's assume that the XML received is like the one in Listing 1:

Listing 1: webserviceorder.xml

8100 99213 2388 Uber Widget 15 10.95 6273 Flangeoid 10 52.00

Now, our order system needs a slightly different format. All we need to do is convert the order received from the Web service into this format in Listing 2.

Listing 2: applicationorder.xml

99213 8100 2388 10.95 15 164.25 6273 52.00 10 520

Translation

Because this is a simplified example, there are only a few things we need to do with the XSL template when converting the format. The first thing we need to notice is that we have to map some elements:

Map Order to NewOrder

Map AccountNumber to CustomerAccountNumber

Map OrderNumber to CustomerOrderNumber

Map Item to OrderItem

Map PricePer to CustomerPrice

Then we need to rearrange the OrderItem element under a new element called OrderItems. Finally, we add a new element called Subtotal, which is calculated based on the unit price and quantity.

Mapping translation is the easiest because you simply define a new element in the template and indicate that the new element has a value from the element in the received XML document. The reordering of Items is achieved by putting Item subtemplate calls into a new element called OrderItems. Finally, a simple XPath expression is used to evaluate. Listing 3 shows the XSL document used to convert the received XML into XML for the application.

Listing 3: translate.xsl

The above is all the content of the article "how to use XSL to translate Web service applications". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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