如何从输入xml文件中获取xslt文件?

时间:2014-09-07 15:19:16

标签: xml xslt

在我的java代码中,我使用以下输入:

<offers>
  <offer>
    <offerDetails>
    <offerCode>AlertsecTotalEndpointSecurity</offerCode>
    <Locale value="en_US">
    <offerName>Alertsec Total Endpoint Security</offerName>
    <offerDescription>Alertsec Total Endpoint Security</offerDescription>
    <usagePrice></usagePrice>
         <compare>0</compare>
       <customize>0</customize>
    <unitPriceDesc>User</unitPriceDesc>

    </Locale>
   <offerprices>
   <offerprice type="ISV">
     <priceid>FD31086465874D5BE0437E0910AC671A</priceid>
     <parentpriceid></parentpriceid>
     <minQty>10</minQty>
     <staticQuantity>N</staticQuantity>
     <minRetailPrice>0</minRetailPrice>
     <isprivate>N</isprivate>
     <isbundle>N</isbundle>
     <currencyid>1001</currencyid>
     <charges>
      <charge>
    <chargetype>
      <chargetypeid>JCB_CHRG_TYP_00001</chargetypeid>
    </chargetype>
    <chargeid>FD31086465894D5BE0437E0910AC671A</chargeid>
    <chargeperiodid>JCB_CHRG_PER_00002</chargeperiodid>
    <ratingtype>RF</ratingtype>
    <charge_calculation>S</charge_calculation>
    <entity_type>OFFERPRICE</entity_type>
    <prorate_on_cancellation>Y</prorate_on_cancellation>
    <balanceimpacts>
      <balanceimpact>
        <scaledPrice>1</scaledPrice>
        <fixedPrice>0</fixedPrice>
        <unitqty>1</unitqty>
        <prorate>Y</prorate>
        <resourceid>1001</resourceid>
        <resourcetype>CURRENCY</resourcetype>
        <pricetype>A</pricetype>
      </balanceimpact>
    </balanceimpacts>
      </charge>
      <charge>
    <chargetype>
      <chargetypeid>JCB_CHRG_TYP_00002</chargetypeid>
    </chargetype>
    <chargeid>FD310864658D4D5BE0437E0910AC671A</chargeid>
    <chargeperiodid>JCB_CHRG_PER_00005</chargeperiodid>
    <ratingtype>O</ratingtype>
    <charge_calculation>S</charge_calculation>
    <entity_type>OFFERPRICE</entity_type>
    <prorate_on_cancellation>Y</prorate_on_cancellation>
    <balanceimpacts>
      <balanceimpact>
        <scaledPrice>0</scaledPrice>
        <fixedPrice>0</fixedPrice>
        <unitqty>1</unitqty>
        <prorate>Y</prorate>
        <resourceid>1001</resourceid>
        <resourcetype>CURRENCY</resourcetype>
        <pricetype>A</pricetype>
      </balanceimpact>
    </balanceimpacts>
      </charge>
     </charges>
   </offerprice>
   <offerprice type="ISV">
     <priceid>FD30096C19AB4681E0437E0910ACD407</priceid>
     <parentpriceid></parentpriceid>
     <minQty>10</minQty>
     <staticQuantity>N</staticQuantity>
     <minRetailPrice>0</minRetailPrice>
     <isprivate>N</isprivate>
     <isbundle>N</isbundle>
     <currencyid>1000</currencyid>
     <charges>
      <charge>
    <chargetype>
      <chargetypeid>JCB_CHRG_TYP_00001</chargetypeid>
    </chargetype>
    <chargeid>FD30096C19AD4681E0437E0910ACD407</chargeid>
    <chargeperiodid>JCB_CHRG_PER_00002</chargeperiodid>
    <ratingtype>RF</ratingtype>
    <charge_calculation>S</charge_calculation>
    <entity_type>OFFERPRICE</entity_type>
    <prorate_on_cancellation>Y</prorate_on_cancellation>
    <balanceimpacts>
      <balanceimpact>
        <scaledPrice>1</scaledPrice>
        <fixedPrice>0</fixedPrice>
        <unitqty>1</unitqty>
        <prorate>Y</prorate>
        <resourceid>1000</resourceid>
        <resourcetype>CURRENCY</resourcetype>
        <pricetype>A</pricetype>
      </balanceimpact>
    </balanceimpacts>
      </charge>
      <charge>
    <chargetype>
      <chargetypeid>JCB_CHRG_TYP_00002</chargetypeid>
    </chargetype>
    <chargeid>FD30096C19B14681E0437E0910ACD407</chargeid>
    <chargeperiodid>JCB_CHRG_PER_00005</chargeperiodid>
    <ratingtype>O</ratingtype>
    <charge_calculation>S</charge_calculation>
    <entity_type>OFFERPRICE</entity_type>
    <prorate_on_cancellation>Y</prorate_on_cancellation>
    <balanceimpacts>
      <balanceimpact>
        <scaledPrice>0</scaledPrice>
        <fixedPrice>0</fixedPrice>
        <unitqty>1</unitqty>
        <prorate>Y</prorate>
        <resourceid>1000</resourceid>
        <resourcetype>CURRENCY</resourcetype>
        <pricetype>A</pricetype>
      </balanceimpact>
    </balanceimpacts>
      </charge>
     </charges>
   </offerprice>
   <offerprice type="MP">
     <priceid>FD30096C19CC4681E0437E0910ACD407</priceid>
     <parentpriceid>FD31086465874D5BE0437E0910AC671A</parentpriceid>
     <minQty>10</minQty>
     <staticQuantity>N</staticQuantity>
     <minRetailPrice>1</minRetailPrice>
     <isprivate>N</isprivate>
     <isbundle>N</isbundle>
     <currencyid>1001</currencyid>
     <charges>
      <charge>
    <chargetype>
      <chargetypeid>JCB_CHRG_TYP_00009</chargetypeid>
    </chargetype>
    <chargeid>FD30096C19CE4681E0437E0910ACD407</chargeid>
    <chargeperiodid>JCB_CHRG_PER_00002</chargeperiodid>
    <ratingtype>RF</ratingtype>
    <charge_calculation>S</charge_calculation>
    <entity_type>OFFERPRICE</entity_type>
    <prorate_on_cancellation>Y</prorate_on_cancellation>
    <balanceimpacts>
      <balanceimpact>
        <scaledPrice>1</scaledPrice>
        <fixedPrice>0</fixedPrice>
        <unitqty>1</unitqty>
        <prorate>Y</prorate>
        <resourceid>1001</resourceid>
        <resourcetype>CURRENCY</resourcetype>
        <pricetype>A</pricetype>
      </balanceimpact>
    </balanceimpacts>
      </charge>
      <charge>
    <chargetype>
      <chargetypeid>JCB_CHRG_TYP_00010</chargetypeid>
    </chargetype>
    <chargeid>FD30096C19D24681E0437E0910ACD407</chargeid>
    <chargeperiodid>JCB_CHRG_PER_00005</chargeperiodid>
    <ratingtype>O</ratingtype>
    <charge_calculation>S</charge_calculation>
    <entity_type>OFFERPRICE</entity_type>
    <prorate_on_cancellation>Y</prorate_on_cancellation>
    <balanceimpacts>
      <balanceimpact>
        <scaledPrice>0</scaledPrice>
        <fixedPrice>0</fixedPrice>
        <unitqty>1</unitqty>
        <prorate>Y</prorate>
        <resourceid>1001</resourceid>
        <resourcetype>CURRENCY</resourcetype>
        <pricetype>A</pricetype>
      </balanceimpact>
    </balanceimpacts>
      </charge>
     </charges>
   </offerprice>
   <offerprice type="MP">
     <priceid>FD310864657D4D5BE0437E0910AC671A</priceid>
     <parentpriceid>FD30096C19AB4681E0437E0910ACD407</parentpriceid>
     <minQty>10</minQty>
     <staticQuantity>N</staticQuantity>
     <minRetailPrice>1</minRetailPrice>
     <isprivate>N</isprivate>
     <isbundle>N</isbundle>
     <currencyid>1000</currencyid>
     <charges>
      <charge>
    <chargetype>
      <chargetypeid>JCB_CHRG_TYP_00009</chargetypeid>
    </chargetype>
    <chargeid>FD310864657F4D5BE0437E0910AC671A</chargeid>
    <chargeperiodid>JCB_CHRG_PER_00002</chargeperiodid>
    <ratingtype>RF</ratingtype>
    <charge_calculation>S</charge_calculation>
    <entity_type>OFFERPRICE</entity_type>
    <prorate_on_cancellation>Y</prorate_on_cancellation>
    <balanceimpacts>
      <balanceimpact>
        <scaledPrice>1</scaledPrice>
        <fixedPrice>0</fixedPrice>
        <unitqty>1</unitqty>
        <prorate>Y</prorate>
        <resourceid>1000</resourceid>
        <resourcetype>CURRENCY</resourcetype>
        <pricetype>A</pricetype>
      </balanceimpact>
    </balanceimpacts>
      </charge>
      <charge>
    <chargetype>
      <chargetypeid>JCB_CHRG_TYP_00010</chargetypeid>
    </chargetype>
    <chargeid>FD31086465834D5BE0437E0910AC671A</chargeid>
    <chargeperiodid>JCB_CHRG_PER_00005</chargeperiodid>
    <ratingtype>O</ratingtype>
    <charge_calculation>S</charge_calculation>
    <entity_type>OFFERPRICE</entity_type>
    <prorate_on_cancellation>Y</prorate_on_cancellation>
    <balanceimpacts>
      <balanceimpact>
        <scaledPrice>0</scaledPrice>
        <fixedPrice>0</fixedPrice>
        <unitqty>1</unitqty>
        <prorate>Y</prorate>
        <resourceid>1000</resourceid>
        <resourcetype>CURRENCY</resourcetype>
        <pricetype>A</pricetype>
      </balanceimpact>
    </balanceimpacts>
      </charge>
     </charges>
   </offerprice>
  </offerprices>
 </offerDetails>

        <paramEntity>   
           <paramName>serviceID</paramName>
            <paramValue>1010065</paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>serviceName</paramName>
            <paramValue>Alertsec Total Endpoint Security</paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>serviceType</paramName>
            <paramValue>Anti-Malware</paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>serviceVendorName</paramName>
            <paramValue>jamcracker</paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>InternalService</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>OrderOfferId</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>OrderOption</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>OrderServiceId</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>Pricing</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>Publisher</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>Resell</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>ResellOfferId</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>ResellRestrict</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>ResellServiceId</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>STP</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>TestDrive</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>TestDriveOfferId</paramName>
            <paramValue></paramValue>
        </paramEntity>
        <paramEntity>   
           <paramName>TestDriveServiceId</paramName>
            <paramValue></paramValue>
        </paramEntity>
</offer>

下面的文件是我的xslt(我到目前为止所做的):

    

    <offerprices>
        <xsl:for-each select="offerprice">
            <xsl:if test="self::node()[@type = $vOfferPriceTypeMP]">

                <offerprice type="MP">
                    <xsl:apply-templates select="priceid" />
                    <parentpriceid></parentpriceid>
                    <xsl:apply-templates select="minQty" />
                    <xsl:apply-templates select="staticQuantity" />
                    <xsl:apply-templates select="minRetailPrice" />
                    <xsl:apply-templates select="isprivate" />
                    <xsl:apply-templates select="isbundle" />
                    <currencyid>1003</currencyid>
                    <inCatalog>Y</inCatalog>
                    <globalPriceOverride>N</globalPriceOverride>
                    <priceChangeIndicator>N</priceChangeIndicator>
                    <offerLevelId>00200D7A6EC69B07E05010AC20090AAE</offerLevelId>

                    <charges>
                        <charge>
                        <xsl:attribute name="typeid">
                            <xsl:value-of select="charges/charge/chargetype/chargetypeid" />
                            </xsl:attribute>

                            <xsl:for-each select="charges/charge">


                                <chargeid>
                                    <xsl:value-of select="chargeid" />
                                </chargeid>
                                <chargeperiodid>
                                    <xsl:value-of select="chargeperiodid" />
                                </chargeperiodid>


                                <ratingtype>
                                    <xsl:value-of select="ratingtype" />
                                </ratingtype>
                                <charge_calculation>
                                    <xsl:value-of select="charge_calculation" />
                                </charge_calculation>
                                <entity_type>
                                    <xsl:value-of select="entity_type" />
                                </entity_type>
                                <setupSKUCode>
                                    <xsl:value-of select="setupSKUCode" />
                                </setupSKUCode>

                                <prorate_on_cancellation>
                                    <xsl:value-of select="prorate_on_cancellation" />
                                </prorate_on_cancellation>


                                <xsl:for-each select="balanceimpacts/balanceimpact">
                                    <balanceimpacts>
                                        <balanceimpact>
                                            <scaledPrice>
                                                <xsl:value-of select="scaledPrice" />
                                            </scaledPrice>
                                            <fixedPrice>
                                                <xsl:value-of select="fixedPrice" />
                                            </fixedPrice>
                                            <unitqty>
                                                <xsl:value-of select="unitqty" />
                                            </unitqty>
                                            <prorate>
                                                <xsl:value-of select="prorate" />
                                            </prorate>
                                            <resourceid>
                                                <xsl:value-of select="resourceid" />
                                            </resourceid>
                                            <resourcetype>
                                                <xsl:value-of select="resourcetype" />
                                            </resourcetype>
                                            <pricetype>
                                                <xsl:value-of select="pricetype" />
                                            </pricetype>
                                        </balanceimpact>
                                    </balanceimpacts>

                                </xsl:for-each>
                            </xsl:for-each>
                        </charge>

                    </charges>

                </offerprice>
            </xsl:if>

            <xsl:if test="self::node()[@type = $vOfferPriceTypeISV]">
                <offerprice type="ISV">
                    <xsl:apply-templates select="priceid" />
                    <parentpriceid />
                    <xsl:apply-templates select="minQty" />
                    <xsl:apply-templates select="staticQuantity" />
                    <xsl:apply-templates select="minRetailPrice" />
                    <xsl:apply-templates select="isprivate" />
                    <xsl:apply-templates select="isbundle" />
                    <currencyid>1003</currencyid>
                    <inCatalog>Y</inCatalog>
                    <globalPriceOverride>N</globalPriceOverride>
                    <priceChangeIndicator>N</priceChangeIndicator>
                    <offerLevelId>00200D7A6EC69B07E05010AC20090AAE</offerLevelId>
                    <charges>
                        <charge>
                            <xsl:attribute name="typeid">
                            <xsl:value-of select="charges/charge/chargetype/chargetypeid" />
                             </xsl:attribute>
                            <xsl:for-each select="charges/charge">


                                <chargeid>
                                    <xsl:value-of select="chargeid" />
                                </chargeid>
                                <chargeperiodid>
                                    <xsl:value-of select="chargeperiodid" />
                                </chargeperiodid>


                                <ratingtype>
                                    <xsl:value-of select="ratingtype" />
                                </ratingtype>
                                <charge_calculation>
                                    <xsl:value-of select="charge_calculation" />
                                </charge_calculation>
                                <entity_type>
                                    <xsl:value-of select="entity_type" />
                                </entity_type>
                                <setupSKUCode>
                                    <xsl:value-of select="setupSKUCode" />
                                </setupSKUCode>
                                <prorate_on_cancellation>
                                    <xsl:value-of select="prorate_on_cancellation" />
                                </prorate_on_cancellation>


                                <xsl:for-each select="balanceimpacts/balanceimpact">
                                    <balanceimpacts>
                                        <balanceimpact>
                                            <scaledPrice>
                                                <xsl:value-of select="scaledPrice" />
                                            </scaledPrice>
                                            <fixedPrice>
                                                <xsl:value-of select="fixedPrice" />
                                            </fixedPrice>
                                            <unitqty>
                                                <xsl:value-of select="unitqty" />
                                            </unitqty>
                                            <prorate>
                                                <xsl:value-of select="prorate" />
                                            </prorate>
                                            <resourceid>
                                                <xsl:value-of select="resourceid" />
                                            </resourceid>
                                            <resourcetype>
                                                <xsl:value-of select="resourcetype" />
                                            </resourcetype>
                                            <pricetype>
                                                <xsl:value-of select="pricetype" />
                                            </pricetype>
                                        </balanceimpact>
                                    </balanceimpacts>

                                </xsl:for-each>
                            </xsl:for-each>
                        </charge>

                    </charges>

                </offerprice>
            </xsl:if>
        </xsl:for-each>
    </offerprices>
  </xsl:template>
</xsl:stylesheet>

我需要输出文件是这样的:

<offerDetails>
    <offerCode>AlertsecTotalEndpointSecuritydummyy</offerCode>
    <Locale value="en_US">
    <offerName>Alertsec Total Endpoint Security dummyy</offerName>
    <offerDescription>Alertsec Total Endpoint Security</offerDescription>
    <unitPriceDesc>User</unitPriceDesc>
    </Locale>
    <currencies>
            <currency>
                <currencyId>1003</currencyId>
            </currency>
        </currencies>
        <offerLevels>
            <offerLevel>
                <offerLevelId>00200D7A6EC69B07E05010AC20090AAE</offerLevelId>
                <name>Default</name>
                <languageCode>en_US</languageCode>
            </offerLevel>
            </offerLevels>

   <offerprices>
   <offerprice type="ISV">
     <priceid>E75AD77694DE439BE043DA0A10AC1840</priceid>
     <parentpriceid></parentpriceid>
     <minQty>1</minQty>
     <staticQuantity>N</staticQuantity>
     <minRetailPrice>0</minRetailPrice>
     <isprivate>N</isprivate>
     <isbundle>N</isbundle>
     <currencyid>1003</currencyid>
     <inCatalog>Y</inCatalog>
    <globalPriceOverride>N</globalPriceOverride>
    <priceChangeIndicator>N</priceChangeIndicator>
    <offerLevelId>00200D7A6EC69B07E05010AC20090AAE</offerLevelId>
     <charges>

 <!-- <charge>
    <chargetype> -->
      <charge typeid="JCB_CHRG_TYP_00001">
     <!--</chargetype> -->
    <chargeid>E75AD77694E0439BE043DA0A10AC1840</chargeid>
    <chargeperiodid>JCB_CHRG_PER_00002</chargeperiodid>
    <ratingtype>RF</ratingtype>
    <charge_calculation>S</charge_calculation>
    <entity_type>OFFERPRICE</entity_type>
    <setupSKUCode></setupSKUCode>
    <prorate_on_cancellation>Y</prorate_on_cancellation>
    <balanceimpacts>
      <balanceimpact>
        <scaledPrice>1</scaledPrice>
        <fixedPrice>0</fixedPrice>
        <unitqty>1</unitqty>
        <prorate>Y</prorate>
        <resourceid>1003</resourceid>
        <resourcetype>CURRENCY</resourcetype>
        <pricetype>A</pricetype>
      </balanceimpact>
    </balanceimpacts>
      </charge>
     <!-- <charge>
    <chargetype> -->
      <charge typeid="JCB_CHRG_TYP_00002">
     <!--</chargetype> -->
    <chargeid>E75AD77694E4439BE043DA0A10AC1840</chargeid>
    <chargeperiodid>JCB_CHRG_PER_00005</chargeperiodid>
    <ratingtype>O</ratingtype>
    <charge_calculation>S</charge_calculation>
    <entity_type>OFFERPRICE</entity_type>
    <setupSKUCode>AlertsecTotalEndpointSecuritydummyy</setupSKUCode>
    <prorate_on_cancellation>Y</prorate_on_cancellation>
    <balanceimpacts>
      <balanceimpact>
        <scaledPrice>1</scaledPrice>
        <fixedPrice>0</fixedPrice>
        <unitqty>1</unitqty>
        <prorate>Y</prorate>
        <resourceid>1000</resourceid>
        <resourcetype>CURRENCY</resourcetype>
        <pricetype>A</pricetype>
      </balanceimpact>
    </balanceimpacts>
      </charge>
     </charges>
   </offerprice>
   <offerprice type="MP">
     <priceid>E75AD77694EF439BE043DA0A10AC1840</priceid>
     <parentpriceid>E75AD77694DE439BE043DA0A10AC1840</parentpriceid>
     <minQty>1</minQty>
     <staticQuantity>N</staticQuantity>
     <minRetailPrice>0</minRetailPrice>
     <isprivate>N</isprivate>
     <isbundle>N</isbundle>
     <currencyid>1003</currencyid>
     <inCatalog>Y</inCatalog>
    <globalPriceOverride>N</globalPriceOverride>
    <priceChangeIndicator>N</priceChangeIndicator>
    <offerLevelId>00200D7A6EC69B07E05010AC20090AAE</offerLevelId>
     <charges>
      <!-- <charge>
    <chargetype> -->
      <charge typeid="JCB_CHRG_TYP_00009">
     <!--</chargetype> -->
    <chargeid>E75AD77694F1439BE043DA0A10AC1840</chargeid>
    <chargeperiodid>JCB_CHRG_PER_00002</chargeperiodid>
    <ratingtype>RF</ratingtype>
    <charge_calculation>S</charge_calculation>
    <entity_type>OFFERPRICE</entity_type>
    <setupSKUCode></setupSKUCode>
    <prorate_on_cancellation>Y</prorate_on_cancellation>
    <balanceimpacts>
      <balanceimpact>
        <scaledPrice>1</scaledPrice>
        <fixedPrice>0</fixedPrice>
        <unitqty>1</unitqty>
        <prorate>Y</prorate>
        <resourceid>1003</resourceid>
        <resourcetype>CURRENCY</resourcetype>
        <pricetype>A</pricetype>
      </balanceimpact>
    </balanceimpacts>
      </charge>
 <!-- <charge>
    <chargetype> -->
      <charge typeid="JCB_CHRG_TYP_00010">
     <!--</chargetype> -->
    <chargeid>E75AD77694F5439BE043DA0A10AC1840</chargeid>
    <chargeperiodid>JCB_CHRG_PER_00005</chargeperiodid>
    <ratingtype>O</ratingtype>
    <charge_calculation>S</charge_calculation>
    <entity_type>OFFERPRICE</entity_type>
    <setupSKUCode>AlertsecTotalEndpointSecuritydummyy</setupSKUCode>
    <prorate_on_cancellation>Y</prorate_on_cancellation>
    <balanceimpacts>
      <balanceimpact>
        <scaledPrice>1</scaledPrice>
        <fixedPrice>0</fixedPrice>
        <unitqty>1</unitqty>
        <prorate>Y</prorate>
        <resourceid>1003</resourceid>
        <resourcetype>CURRENCY</resourcetype>
        <pricetype>A</pricetype>
      </balanceimpact>
    </balanceimpacts>
      </charge>
     </charges>
   </offerprice>
  </offerprices>
 </offerDetails>

我在这里发布我的输入xml文件,xslt文件和输出xml文件,任何人都可以指导我如何使用xslt将输入xml更改为输出xml。

我需要从输入xml转换xslt到输出xml。

2 个答案:

答案 0 :(得分:0)

简短的回答是你没有从任何输入XML获得XSLT。但是在编写XSLT时,您可能需要有关文档的更多信息。例如:

  1. 您想在输入文档中更改的内容是什么?输入和输出看起来非常相似。

  2. 您想要处理哪些其他类型的输入文档? DTD或XML Schema会有所帮助。

  3. 您的Java代码与此有什么关系?

  4. 在分析了想要进行的更改(1)以及要接受的输入类型(2)之后,开发XSLT非常简单。

    顺便说一下,它们不应该被称为“文件”,因为XML文件不是一个明确定义的概念。我们称它们为XML文档(可以存储在0-n文件中)。

答案 1 :(得分:0)

不知道这对你是否有帮助,但我想你只想知道如何将chargetypeid作为每个电荷的属性,而不是仅仅从输入xml中复制它。 不想在这里编写完整的xslt,因为您可以在当前的XSLT中集成部分表单并进一步调整以获取output.xml,因此只需调整相关部分:

<?xml version="1.0"?><xsl:stylesheet 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">
<xsl:template match="/*">
 <xsl:apply-templates select=".//offerprices"/>
</xsl:template>
<xsl:template match="offerprices">
 <offerprices>
  <xsl:apply-templates/>
 </offerprices>
</xsl:template>
<xsl:template match="offerprice">
 <offerprice>
  <xsl:apply-templates select="descendant::charge"/>
 </offerprice>
</xsl:template>
<xsl:template match="charge">
 <xsl:variable name="chargetypeid" 
  select="normalize-space(descendant::chargetypeid/text())"/>
 <charge>
  <xsl:attribute name="chargetypeid" select="$chargetypeid"/>
    <!-- here your adjusted current code -->
 </charge>
 </xsl:template>
</xsl:stylesheet>

输出XML:

 <offerprices>
    <offerprice>
      <charge chargetypeid="JCB_CHRG_TYP_00001"/>
      <charge chargetypeid="JCB_CHRG_TYP_00002"/>
    </offerprice>
    <offerprice>
     <charge chargetypeid="JCB_CHRG_TYP_00009"/>
     <charge chargetypeid="JCB_CHRG_TYP_00010"/>
    </offerprice>
  </offerprices>

在匹配“充电”的模板中,您可以处理其余部分以调整输出 如果您在获取chargetypeid的说明之后没有太多关注XSLT:在匹配“charge”的模板中,每个电荷将被处理为当前节点。使用ax“descendant::”只会寻址此节点的后代,匹配节点“chargetypeid” - descendant::chargetypeid。如果您希望chargetypeid的值作为每次费用的属性,那么您将使用text()获取值,并且为了删除空格,函数normalize-space()会处理这一点。

并且您也不希望将chargetype作为输出中的节点,而只是作为计费属性,只需应用与此节点匹配的empy模板,它将被排除在外:

<xsl:template match="chargetype"/>