本文介绍了如何准备XSLT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我有XML文件如下所示,
Hi All I have XML file As below,
<?xml version="1.0" encoding="utf-8"?>
<OrderConfirmation xmlns="http://www.test.com/ILSNET/2013/" FileName="MD0220140605233218480.xml" UserName="testuser" DateTimeStamp="6/5/2014 11:32:18 PM">
<OrderConfirmRequest JoiningCondition=" FROM SIME_MD02_OrderConfirmationUpload_View WITH(NOLOCK) WHERE [SHIPMENT_HEADER.INTERNAL_SHIPMENT_NUM]=@iIntShipNumber" xmlns="http://www.test.com/ILSNET/2013/">
<APPField FieldName="IShipmentNumber" FieldValue="101" APPColumnName="CAST([SHIPMENT_HEADER.SHIPMENT_ID] AS CHAR(10))" APPTableName="SHIPMENT_HEADER" />
<APPField FieldName="referenceDocumentNumber" FieldValue="SP25" APPColumnName="CAST([SHIPMENT_HEADER.SHIPMENT_ID] AS CHAR(10))" APPTableName="SHIPMENT_HEADER" />
<APPField FieldName="totalCost" FieldValue="1.00000" APPColumnName="CAST([SHIPMENT_HEADER.USER_DEF7] as decimal(19,5))" APPTableName="SHIPMENT_HEADER" />
</OrderConfirmRequest>
<OrderConfirmRequest JoiningCondition=" FROM SIME_MD02_OrderConfirmationUpload_View WITH(NOLOCK) WHERE [SHIPMENT_HEADER.INTERNAL_SHIPMENT_NUM]=@iIntShipNumber" xmlns="http://www.test.com/ILSNET/2013/">
<APPField FieldName="IShipmentNumber" FieldValue="102" APPColumnName="CAST([SHIPMENT_HEADER.SHIPMENT_ID] AS CHAR(10))" APPTableName="SHIPMENT_HEADER" />
<APPField FieldName="referenceDocumentNumber" FieldValue="SP26 " APPColumnName="CAST([SHIPMENT_HEADER.SHIPMENT_ID] AS CHAR(10))" APPTableName="SHIPMENT_HEADER" />
<APPField FieldName="totalCost" FieldValue="2.00000" APPColumnName="CAST([SHIPMENT_HEADER.USER_DEF7] as decimal(19,5))" APPTableName="SHIPMENT_HEADER" />
</OrderConfirmRequest>
<OrderConfirmContainer JoiningCondition=" FROM SIME_MD02_OrderConfirmationUpload_View WITH(NOLOCK) WHERE [SHIPMENT_HEADER.INTERNAL_SHIPMENT_NUM]=@iIntShipNumber" xmlns="http://www.test.com/ILSNET/2013/">
<APPField FieldName="IShipmentNumber" FieldValue="101" APPColumnName="LEFT([SHIPPING_CONTAINER.CONTAINER_ID],25)" APPTableName="SHIPPING_CONTAINER" />
<APPField FieldName="containerID" FieldValue="C1" APPColumnName="LEFT([SHIPPING_CONTAINER.CONTAINER_ID],25)" APPTableName="SHIPPING_CONTAINER" />
<APPField FieldName="tyPack" FieldValue="PACK1" APPColumnName="LEFT([SHIPPING_CONTAINER.CONTAINER_TYPE],25)" APPTableName="SHIPPING_CONTAINER" />
</OrderConfirmContainer>
<OrderConfirmContainer JoiningCondition=" FROM SIME_MD02_OrderConfirmationUpload_View WITH(NOLOCK) WHERE [SHIPMENT_HEADER.INTERNAL_SHIPMENT_NUM]=@iIntShipNumber" xmlns="http://www.test.com/ILSNET/2013/">
<APPField FieldName="IShipmentNumber" FieldValue="102" APPColumnName="LEFT([SHIPPING_CONTAINER.CONTAINER_ID],25)" APPTableName="SHIPPING_CONTAINER" />
<APPField FieldName="containerID" FieldValue="C2" APPColumnName="LEFT([SHIPPING_CONTAINER.CONTAINER_ID],25)" APPTableName="SHIPPING_CONTAINER" />
<APPField FieldName="tyPack" FieldValue="PACK2" APPColumnName="LEFT([SHIPPING_CONTAINER.CONTAINER_TYPE],25)" APPTableName="SHIPPING_CONTAINER" />
</OrderConfirmContainer>
<OrderConfirmDetail JoiningCondition=" FROM SIME_MD02_OrderConfirmationUpload_View WITH(NOLOCK) WHERE [SHIPMENT_HEADER.INTERNAL_SHIPMENT_NUM]=@iIntShipNumber" xmlns="http://www.test.com/ILSNET/2013/">
<APPField FieldName="IShipmentNumber" FieldValue="101" APPColumnName="CAST([SHIPMENT_DETAIL.USER_DEF2] as decimal(3))" APPTableName="SHIPMENT_DETAIL" />
<APPField FieldName="lineNumber" FieldValue="1" APPColumnName="CAST([SHIPMENT_DETAIL.USER_DEF2] as decimal(3))" APPTableName="SHIPMENT_DETAIL" />
</OrderConfirmDetail>
<OrderConfirmDetail JoiningCondition=" FROM SIME_MD02_OrderConfirmationUpload_View WITH(NOLOCK) WHERE [SHIPMENT_HEADER.INTERNAL_SHIPMENT_NUM]=@iIntShipNumber" xmlns="http://www.test.com/ILSNET/2013/">
<APPField FieldName="IShipmentNumber" FieldValue="102" APPColumnName="CAST([SHIPMENT_DETAIL.USER_DEF2] as decimal(3))" APPTableName="SHIPMENT_DETAIL" />
<APPField FieldName="lineNumber" FieldValue="2" APPColumnName="CAST([SHIPMENT_DETAIL.USER_DEF2] as decimal(3))" APPTableName="SHIPMENT_DETAIL" />
</OrderConfirmDetail>
</OrderConfirmation>
我需要生成如下XML文件,
I need to generate XML file as below,
<?xml version="1.0" encoding="utf-8"?>
<OrderConfirmation xmlns="http://www.test.com/ILSNET/2013/" FileName="MD0220140605233218480.xml" UserName="testuser" DateTimeStamp="6/5/2014 11:32:18 PM">
<OrderConfirmRequest JoiningCondition=" FROM SIME_MD02_OrderConfirmationUpload_View WITH(NOLOCK) WHERE [SHIPMENT_HEADER.INTERNAL_SHIPMENT_NUM]=@iIntShipNumber" xmlns="http://www.test.com/ILSNET/2013/">
<APPField FieldName="IShipmentNumber" FieldValue="101" APPColumnName="CAST([SHIPMENT_HEADER.SHIPMENT_ID] AS CHAR(10))" APPTableName="SHIPMENT_HEADER" />
<APPField FieldName="referenceDocumentNumber" FieldValue="SP25" APPColumnName="CAST([SHIPMENT_HEADER.SHIPMENT_ID] AS CHAR(10))" APPTableName="SHIPMENT_HEADER" />
<APPField FieldName="totalCost" FieldValue="1.00000" APPColumnName="CAST([SHIPMENT_HEADER.USER_DEF7] as decimal(19,5))" APPTableName="SHIPMENT_HEADER" />
<OrderConfirmContainer JoiningCondition=" FROM SIME_MD02_OrderConfirmationUpload_View WITH(NOLOCK) WHERE [SHIPMENT_HEADER.INTERNAL_SHIPMENT_NUM]=@iIntShipNumber" xmlns="http://www.test.com/ILSNET/2013/">
<APPField FieldName="IShipmentNumber" FieldValue="101" APPColumnName="LEFT([SHIPPING_CONTAINER.CONTAINER_ID],25)" APPTableName="SHIPPING_CONTAINER" />
<APPField FieldName="containerID" FieldValue="C1" APPColumnName="LEFT([SHIPPING_CONTAINER.CONTAINER_ID],25)" APPTableName="SHIPPING_CONTAINER" />
<APPField FieldName="tyPack" FieldValue="PACK1" APPColumnName="LEFT([SHIPPING_CONTAINER.CONTAINER_TYPE],25)" APPTableName="SHIPPING_CONTAINER" />
<OrderConfirmDetail JoiningCondition=" FROM SIME_MD02_OrderConfirmationUpload_View WITH(NOLOCK) WHERE [SHIPMENT_HEADER.INTERNAL_SHIPMENT_NUM]=@iIntShipNumber" xmlns="http://www.test.com/ILSNET/2013/">
<APPField FieldName="IShipmentNumber" FieldValue="101" APPColumnName="CAST([SHIPMENT_DETAIL.USER_DEF2] as decimal(3))" APPTableName="SHIPMENT_DETAIL" />
<APPField FieldName="lineNumber" FieldValue="1" APPColumnName="CAST([SHIPMENT_DETAIL.USER_DEF2] as decimal(3))" APPTableName="SHIPMENT_DETAIL" />
</OrderConfirmDetail>
</OrderConfirmContainer>
</OrderConfirmRequest>
<OrderConfirmRequest JoiningCondition=" FROM SIME_MD02_OrderConfirmationUpload_View WITH(NOLOCK) WHERE [SHIPMENT_HEADER.INTERNAL_SHIPMENT_NUM]=@iIntShipNumber" xmlns="http://www.test.com/ILSNET/2013/">
<APPField FieldName="IShipmentNumber" FieldValue="102" APPColumnName="CAST([SHIPMENT_HEADER.SHIPMENT_ID] AS CHAR(10))" APPTableName="SHIPMENT_HEADER" />
<APPField FieldName="referenceDocumentNumber" FieldValue="SP26 " APPColumnName="CAST([SHIPMENT_HEADER.SHIPMENT_ID] AS CHAR(10))" APPTableName="SHIPMENT_HEADER" />
<APPField FieldName="totalCost" FieldValue="2.00000" APPColumnName="CAST([SHIPMENT_HEADER.USER_DEF7] as decimal(19,5))" APPTableName="SHIPMENT_HEADER" />
<OrderConfirmContainer JoiningCondition=" FROM SIME_MD02_OrderConfirmationUpload_View WITH(NOLOCK) WHERE [SHIPMENT_HEADER.INTERNAL_SHIPMENT_NUM]=@iIntShipNumber" xmlns="http://www.test.com/ILSNET/2013/">
<APPField FieldName="IShipmentNumber" FieldValue="102" APPColumnName="LEFT([SHIPPING_CONTAINER.CONTAINER_ID],25)" APPTableName="SHIPPING_CONTAINER" />
<APPField FieldName="containerID" FieldValue="C2" APPColumnName="LEFT([SHIPPING_CONTAINER.CONTAINER_ID],25)" APPTableName="SHIPPING_CONTAINER" />
<APPField FieldName="tyPack" FieldValue="PACK2" APPColumnName="LEFT([SHIPPING_CONTAINER.CONTAINER_TYPE],25)" APPTableName="SHIPPING_CONTAINER" />
<OrderConfirmDetail JoiningCondition=" FROM SIME_MD02_OrderConfirmationUpload_View WITH(NOLOCK) WHERE [SHIPMENT_HEADER.INTERNAL_SHIPMENT_NUM]=@iIntShipNumber" xmlns="http://www.test.com/ILSNET/2013/">
<APPField FieldName="IShipmentNumber" FieldValue="102" APPColumnName="CAST([SHIPMENT_DETAIL.USER_DEF2] as decimal(3))" APPTableName="SHIPMENT_DETAIL" />
<APPField FieldName="lineNumber" FieldValue="2" APPColumnName="CAST([SHIPMENT_DETAIL.USER_DEF2] as decimal(3))" APPTableName="SHIPMENT_DETAIL" />
</OrderConfirmDetail>
</OrderConfirmContainer>
</OrderConfirmRequest>
</OrderConfirmation>
I have sample XSLT as below,
I have sample XSLT as below,
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:APP="http://www.manh.com/ILSNET/2013/">
<xsl:output method="xml"/>
<xsl:template match="APP:OrderConfirmation">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://www.acndms.com/HD/WMS/Interface">
<!--<soapenv:Header/>-->
<OrderConfirmation>
<xsl:for-each select="./APP:OrderConfirmRequest">
<xsl:variable name="iSH" select="position()"/>
<xsl:variable name="ISHNumber"><xsl:value-of select="(//APP:OrderConfirmRequest/APP:APPField[@FieldName = 'IShipmentNumber']/@FieldValue)[$iSH]"/></xsl:variable>
<OrderConfirmRequest>
<referenceDocumentNumber>
<xsl:value-of disable-output-escaping="yes" select="(//APP:OrderConfirmRequest/APP:APPField[@FieldName = 'referenceDocumentNumber']/@FieldValue)[$iSH]"/>
</referenceDocumentNumber>
<totalCost>
<xsl:value-of disable-output-escaping="yes" select="(//APP:OrderConfirmRequest/APP:APPField[@FieldName = 'totalCost']/@FieldValue)[$iSH]"/>
</totalCost>
<xsl:for-each select="//APP:OrderConfirmContainer//APP:APPField[@FieldName = 'IShipmentNumber']/@FieldValue">
<xsl:variable name="iSC" select="position()"/>
<orderConfirmContainer>
<containerId>
<xsl:value-of disable-output-escaping="yes" select="(//APP:OrderConfirmContainer/APP:APPField[@FieldName = 'containerId']/@FieldValue)[$iSC]"/>
</containerId>
<tyPack>
<xsl:value-of disable-output-escaping="yes" select="(//APP:OrderConfirmContainer/APP:APPField[@FieldName = 'tyPack']/@FieldValue)[$iSC]"/>
</tyPack>
<xsl:for-each select="//APP:OrderConfirmContainer//APP:OrderConfirmContainer//APP:OrderConfirmDetail[@FieldName = 'IShipmentNumber']/@FieldValue">
<xsl:variable name="i" select="position()"/>
<orderConfirmDetails>
<lineNumber>
<xsl:value-of disable-output-escaping="yes" select="(//APP:OrderConfirmDetail/APP:APPField[@FieldName = 'lineNumber']/@FieldValue)[$i]"/>
</lineNumber>
<lineNumberSuffix>
<xsl:value-of disable-output-escaping="yes" select="(//APP:OrderConfirmDetail/APP:APPField[@FieldName = 'lineNumberSuffix']/@FieldValue)[$i]"/>
</lineNumberSuffix>
</orderConfirmDetails>
</xsl:for-each>
</orderConfirmContainer>
</xsl:for-each>
</OrderConfirmRequest>
</xsl:for-each>
</OrderConfirmation>
</soapenv:Envelope>
</xsl:template>
<xsl:template name="padRight">
<xsl:param name="stringToPad" />
<xsl:param name="length" select="0" />
<xsl:param name="chars" select="' '" />
<xsl:choose>
<xsl:when test="not($length) or not($chars) or 0 > $length">
<xsl:value-of disable-output-escaping="yes" select="$stringToPad" />
</xsl:when>
<xsl:otherwise>
<xsl:variable name="string" select="concat($stringToPad, $chars, $chars, $chars, $chars, $chars, $chars, $chars, $chars, $chars)" />
<xsl:choose>
<xsl:when test="string-length($string) >= $length">
<xsl:value-of disable-output-escaping="yes" select="substring($string, 1, $length)" />
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="padRight">
<xsl:with-param name="stringToPad" select="$string" />
<xsl:with-param name="length" select="$length" />
<xsl:with-param name="chars" select="$chars" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Please help me how i can create XSLT File to get expected XML file.(if any tool/code)
It is very urgent for me.
Thanks in advance.
Please help me how i can create XSLT File to get expected XML file.(if any tool/code)
It is very urgent for me.
Thanks in advance.
推荐答案
这篇关于如何准备XSLT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!