1

私は完全に立ち往生しています。XLSTを使用してxml出力ファイルの一部を検索/置換しようとしています。私には本当に出発点さえありません。Altova DiffDogを使用して、xlstを自動的に生成しようとしました。これは、自分でxlstを作成する方法をしっかりと把握していないためです。

これは私の現在のxml出力ファイルです:

<?xml version='1.0' encoding='UTF-8'?>
<BB:Report_Data xmlns:BB="urn:com.playdate.report/Report-Outbound">
   <BB:Report_Entry>
      <BB:leaveBalanceTotal.employeeId>1234567</BB:leaveBalanceTotal.employeeId>
      <BB:leaveBalanceTotal.bmbId>9280136270</BB:leaveBalanceTotal.bmbId>
      <BB:All_Eligible_Time_Off_Plans_for_Worker>
         <BB:leaveBalanceTotal.leaveCodeId>1010</BB:leaveBalanceTotal.leaveCodeId>
         <BB:leaveBalanceTotal.balanceAmount>0</BB:leaveBalanceTotal.balanceAmount>
         <BB:leaveBalanceTotal.effectiveDate>2012-07-05</BB:leaveBalanceTotal.effectiveDate>
         <BB:leaveBalanceTotal.lastPayEndDate>2012-07-05</BB:leaveBalanceTotal.lastPayEndDate>
      </BB:All_Eligible_Time_Off_Plans_for_Worker>
      <BB:All_Eligible_Time_Off_Plans_for_Worker>
         <BB:leaveBalanceTotal.leaveCodeId>1014</BB:leaveBalanceTotal.leaveCodeId>
         <BB:leaveBalanceTotal.balanceAmount>96</BB:leaveBalanceTotal.balanceAmount>
         <BB:leaveBalanceTotal.effectiveDate>2012-07-05</BB:leaveBalanceTotal.effectiveDate>
         <BB:leaveBalanceTotal.lastPayEndDate>2012-07-05</BB:leaveBalanceTotal.lastPayEndDate>
      </BB:All_Eligible_Time_Off_Plans_for_Worker>
      <BB:leaveBalanceTotal.totalDaysService>1459</BB:leaveBalanceTotal.totalDaysService>
   </BB:Report_Entry>
</BB:Report_Data>

これは私がそれをどのように見えるようにする必要があるかです:

<?xml version='1.0' encoding='UTF-8'?>
<BB:Report_Data xmlns:BB="urn:com.playdate.report/Report-Outbound">
   <leaveBalanceTotal>
      <leaveBalanceTotal.employeeId>1234567</leaveBalanceTotal.employeeId>
      <leaveBalanceTotal.bmbId>9280136270</leaveBalanceTotal.bmbId>
      <leaveBalanceTotal.leaveCodeId>1010</leaveBalanceTotal.leaveCodeId>
      <leaveBalanceTotal.balanceAmount>0</leaveBalanceTotal.balanceAmount>
      <leaveBalanceTotal.effectiveDate>2012-07-05</leaveBalanceTotal.effectiveDate>
      <leaveBalanceTotal.lastPayEndDate>2012-07-05</leaveBalanceTotal.lastPayEndDate>
      <leaveBalanceTotal.leaveCodeId>1014</leaveBalanceTotal.leaveCodeId>
      <leaveBalanceTotal.balanceAmount>96</leaveBalanceTotal.balanceAmount>
      <leaveBalanceTotal.effectiveDate>2012-07-05</leaveBalanceTotal.effectiveDate>
      <leaveBalanceTotal.lastPayEndDate>2012-07-05</leaveBalanceTotal.lastPayEndDate>
      <leaveBalanceTotal.totalDaysService>1459</leaveBalanceTotal.totalDaysService>
   </leaveBalanceTotal>
</BB:Report_Data>

基本的に、私は次のすべての発生を削除しようとしています:

  1. BB:All_Eligible_Time_Off_Plans_for_Worker
  2. / BB:All_Eligible_Time_Off_Plans_for_Worker
  3. BB:

そして、Report_EntryをleaveBalanceTotalに置き換える必要があります。

どんな助けでもいただければ幸いです!

4

2 に答える 2

0

この XSLT の場合:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
  xmlns:BB="urn:com.playdate.report/Report-Outbound"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output omit-xml-declaration="no" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <!-- Identity Template: copies everything as-is -->
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <!-- Remove BB:All_Eligible_Time_Off_Plans_for_Worker elements -->
  <!-- right away, but process their children -->
  <xsl:template match="BB:All_Eligible_Time_Off_Plans_for_Worker" priority="2">
    <xsl:apply-templates /> 
  </xsl:template>

  <!-- Replace BB:Report_Entry elements with leaveBalanceTotal ones -->
  <xsl:template match="BB:Report_Entry">
    <leaveBalanceTotal>
      <xsl:apply-templates />   
    </leaveBalanceTotal>    
  </xsl:template>

  <!-- Remove BB namespace from descendent elements -->
  <xsl:template match="BB:Report_Entry/* | 
      BB:All_Eligible_Time_Off_Plans_for_Worker/*">
    <xsl:element name="{local-name(.)}">
      <xsl:apply-templates />   
    </xsl:element>  
  </xsl:template>

</xsl:stylesheet>

...提供された XML に適用されます。

<?xml version="1.0" encoding="UTF-8"?>
<BB:Report_Data xmlns:BB="urn:com.playdate.report/Report-Outbound">
  <BB:Report_Entry>
    <BB:leaveBalanceTotal.employeeId>1234567</BB:leaveBalanceTotal.employeeId>
    <BB:leaveBalanceTotal.bmbId>9280136270</BB:leaveBalanceTotal.bmbId>
    <BB:All_Eligible_Time_Off_Plans_for_Worker>
      <BB:leaveBalanceTotal.leaveCodeId>1010</BB:leaveBalanceTotal.leaveCodeId>
      <BB:leaveBalanceTotal.balanceAmount>0</BB:leaveBalanceTotal.balanceAmount>
      <BB:leaveBalanceTotal.effectiveDate>2012-07-05</BB:leaveBalanceTotal.effectiveDate>
      <BB:leaveBalanceTotal.lastPayEndDate>2012-07-05</BB:leaveBalanceTotal.lastPayEndDate>
    </BB:All_Eligible_Time_Off_Plans_for_Worker>
    <BB:All_Eligible_Time_Off_Plans_for_Worker>
      <BB:leaveBalanceTotal.leaveCodeId>1014</BB:leaveBalanceTotal.leaveCodeId>
      <BB:leaveBalanceTotal.balanceAmount>96</BB:leaveBalanceTotal.balanceAmount>
      <BB:leaveBalanceTotal.effectiveDate>2012-07-05</BB:leaveBalanceTotal.effectiveDate>
      <BB:leaveBalanceTotal.lastPayEndDate>2012-07-05</BB:leaveBalanceTotal.lastPayEndDate>
    </BB:All_Eligible_Time_Off_Plans_for_Worker>
    <BB:leaveBalanceTotal.totalDaysService>1459</BB:leaveBalanceTotal.totalDaysService>
  </BB:Report_Entry>
</BB:Report_Data>

...期待される結果が生成されます。

<?xml version="1.0" encoding="UTF-8"?>
<BB:Report_Data xmlns:BB="urn:com.playdate.report/Report-Outbound">
  <leaveBalanceTotal>
    <leaveBalanceTotal.employeeId>1234567</leaveBalanceTotal.employeeId>
    <leaveBalanceTotal.bmbId>9280136270</leaveBalanceTotal.bmbId>
    <leaveBalanceTotal.leaveCodeId>1010</leaveBalanceTotal.leaveCodeId>
    <leaveBalanceTotal.balanceAmount>0</leaveBalanceTotal.balanceAmount>
    <leaveBalanceTotal.effectiveDate>2012-07-05</leaveBalanceTotal.effectiveDate>
    <leaveBalanceTotal.lastPayEndDate>2012-07-05</leaveBalanceTotal.lastPayEndDate>
    <leaveBalanceTotal.leaveCodeId>1014</leaveBalanceTotal.leaveCodeId>
    <leaveBalanceTotal.balanceAmount>96</leaveBalanceTotal.balanceAmount>
    <leaveBalanceTotal.effectiveDate>2012-07-05</leaveBalanceTotal.effectiveDate>
    <leaveBalanceTotal.lastPayEndDate>2012-07-05</leaveBalanceTotal.lastPayEndDate>
    <leaveBalanceTotal.totalDaysService>1459</leaveBalanceTotal.totalDaysService>
  </leaveBalanceTotal>
</BB:Report_Data>

それが役立つことを願っています! ご不明な点がございましたら、お知らせください。

于 2012-07-13T17:32:44.003 に答える
0

別の XSLT 1.0 オプションを次に示します。これは、データが持つ可能性のある属性も保持します。

XSLT1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:BB="urn:com.playdate.report/Report-Outbound" 
    exclude-result-prefixes="BB">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="comment()|processing-instruction()|@*">
        <xsl:copy/>
    </xsl:template>

    <xsl:template match="*">
        <xsl:element name="{local-name()}">
            <xsl:apply-templates select="node()|@*"/>
        </xsl:element>
    </xsl:template>

    <xsl:template match="BB:All_Eligible_Time_Off_Plans_for_Worker">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="BB:Report_Data">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="BB:Report_Entry">
        <leaveBalanceTotal>
            <xsl:apply-templates select="node()|@*"/>
        </leaveBalanceTotal>
    </xsl:template>

</xsl:stylesheet>

出力

<BB:Report_Data xmlns:BB="urn:com.playdate.report/Report-Outbound">
   <leaveBalanceTotal>
      <leaveBalanceTotal.employeeId>1234567</leaveBalanceTotal.employeeId>
      <leaveBalanceTotal.bmbId>9280136270</leaveBalanceTotal.bmbId>
      <leaveBalanceTotal.leaveCodeId>1010</leaveBalanceTotal.leaveCodeId>
      <leaveBalanceTotal.balanceAmount>0</leaveBalanceTotal.balanceAmount>
      <leaveBalanceTotal.effectiveDate>2012-07-05</leaveBalanceTotal.effectiveDate>
      <leaveBalanceTotal.lastPayEndDate>2012-07-05</leaveBalanceTotal.lastPayEndDate>
      <leaveBalanceTotal.leaveCodeId>1014</leaveBalanceTotal.leaveCodeId>
      <leaveBalanceTotal.balanceAmount>96</leaveBalanceTotal.balanceAmount>
      <leaveBalanceTotal.effectiveDate>2012-07-05</leaveBalanceTotal.effectiveDate>
      <leaveBalanceTotal.lastPayEndDate>2012-07-05</leaveBalanceTotal.lastPayEndDate>
      <leaveBalanceTotal.totalDaysService>1459</leaveBalanceTotal.totalDaysService>
   </leaveBalanceTotal>
</BB:Report_Data>
于 2012-07-13T17:39:39.823 に答える