2011-11-07 30 views
6

मेरी आवश्यकता सिर्फ "नाम" के विशेषता मान को दोबारा विभाजित करने के लिए है। यदि इस विशेषता के मान के रूप में "डिफ़ॉल्ट" है, तो इसे "नया" में बदला जाना चाहिए। बाकी सब कुछ इनपुट एक्सएमएल की प्रति होना चाहिए। मैंने नीचे xsl के साथ प्रयास किया हालांकि यह काम नहीं कर रहा है।किसी विशेष विशेषता का मान बदलें

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" indent="yes"/> 

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

    <xsl:template match="SORRegion[@name='default']"> 
    <xsl:attribute name="name"> 
    <xsl:value-of select="'New'"/> 
    </xsl:attribute> 
    <xsl:copy-of select="child::*"/> 
    </xsl:template> 

</xsl:stylesheet> 

इनपुट एक्सएमएल

<RoutingDetails> 
    <Service ServiceName="StatementIndicatorsService"> 
     <SOR SORname="Globestar"> 
      <CountryCode Ctrycd="124"> 
       <SORRegion name="Test"> 
        <ConsumerName name="MYCA"> 
         <AutomationIds> 
          <PreAutoId> 
           <AutomationId>XA1146A</AutomationId> 
           <AutomationId>XA1146A</AutomationId> 
          </PreAutoId> 
          <DefaultAutoId> 
           <AutomationId>XA1146A</AutomationId> 
          </DefaultAutoId> 
         </AutomationIds> 
        </ConsumerName> 
        <QueueDetails> 
         <QueueManager>MAO1</QueueManager> 
         <ReplyQueueManager>MAO1</ReplyQueueManager> 
         <RequestQueue>GSTAR.ICS.DP.DHIPO211.REQUEST</RequestQueue> 
         <ReplyQueue>ICS.DP.REPLY</ReplyQueue> 
        </QueueDetails> 

       </SORRegion> 
       <SORRegion name="default"> 
        <ConsumerName name="MYCA"> 
         <AutomationIds> 
          <PreAutoId> 
           <AutomationId>XA1146A</AutomationId> 
           <AutomationId>XA1146A</AutomationId> 
          </PreAutoId> 
          <DefaultAutoId> 
           <AutomationId>XA1146A</AutomationId> 
          </DefaultAutoId> 
         </AutomationIds> 
        </ConsumerName> 
        <QueueDetails> 
         <QueueManager>MAO1</QueueManager> 
         <ReplyQueueManager>MAO1</ReplyQueueManager> 
         <RequestQueue>DEFAULT.REQUEST</RequestQueue> 
         <ReplyQueue>ICS.DP.REPLY</ReplyQueue> 
        </QueueDetails> 

       </SORRegion> 
      </CountryCode> 
     </SOR> 
    </Service> 
</RoutingDetails> 

उत्तर

9
<xsl:template match="SORRegion[@name='default']"> 
    <xsl:attribute name="name"> 
     <xsl:value-of select="'New'"/> 
    </xsl:attribute> 
    <xsl:copy-of select="child::*"/> 
    </xsl:template> 

इस कोड के साथ समस्याओं का एक संख्या में हैं। सबसे महत्वपूर्ण समस्या यह है कि यह वर्तमान नोड (SORRegion तत्व) हटा देता है और इसे केवल एक विशेषता के साथ बदल देता है।

समाधान अद्यतन की गई विशेषता से मेल खाना है।

यह परिवर्तन:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 
<xsl:strip-space elements="*"/> 

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

<xsl:template match="SORRegion/@name[.='default']"> 
    <xsl:attribute name="name"> 
    <xsl:value-of select="'New'"/> 
    </xsl:attribute> 
</xsl:template> 
</xsl:stylesheet> 

जब प्रदान की XML दस्तावेज़ पर लागू:

<RoutingDetails> 
    <Service ServiceName="StatementIndicatorsService"> 
     <SOR SORname="Globestar"> 
     <CountryCode Ctrycd="124"> 
      <SORRegion name="Test"> 
       <ConsumerName name="MYCA"> 
        <AutomationIds> 
        <PreAutoId> 
         <AutomationId>XA1146A</AutomationId> 
         <AutomationId>XA1146A</AutomationId> 
        </PreAutoId> 
        <DefaultAutoId> 
         <AutomationId>XA1146A</AutomationId> 
        </DefaultAutoId> 
        </AutomationIds> 
       </ConsumerName> 
       <QueueDetails> 
        <QueueManager>MAO1</QueueManager> 
        <ReplyQueueManager>MAO1</ReplyQueueManager> 
        <RequestQueue>GSTAR.ICS.DP.DHIPO211.REQUEST</RequestQueue> 
        <ReplyQueue>ICS.DP.REPLY</ReplyQueue> 
       </QueueDetails> 
      </SORRegion> 
      <SORRegion name="New"> 
       <ConsumerName name="MYCA"> 
        <AutomationIds> 
        <PreAutoId> 
         <AutomationId>XA1146A</AutomationId> 
         <AutomationId>XA1146A</AutomationId> 
        </PreAutoId> 
        <DefaultAutoId> 
         <AutomationId>XA1146A</AutomationId> 
        </DefaultAutoId> 
        </AutomationIds> 
       </ConsumerName> 
       <QueueDetails> 
        <QueueManager>MAO1</QueueManager> 
        <ReplyQueueManager>MAO1</ReplyQueueManager> 
        <RequestQueue>DEFAULT.REQUEST</RequestQueue> 
        <ReplyQueue>ICS.DP.REPLY</ReplyQueue> 
       </QueueDetails> 
      </SORRegion> 
     </CountryCode> 
     </SOR> 
    </Service> 
</RoutingDetails> 
:

<RoutingDetails> 
    <Service ServiceName="StatementIndicatorsService"> 
     <SOR SORname="Globestar"> 
      <CountryCode Ctrycd="124"> 
       <SORRegion name="Test"> 
        <ConsumerName name="MYCA"> 
         <AutomationIds> 
          <PreAutoId> 
           <AutomationId>XA1146A</AutomationId> 
           <AutomationId>XA1146A</AutomationId> 
          </PreAutoId> 
          <DefaultAutoId> 
           <AutomationId>XA1146A</AutomationId> 
          </DefaultAutoId> 
         </AutomationIds> 
        </ConsumerName> 
        <QueueDetails> 
         <QueueManager>MAO1</QueueManager> 
         <ReplyQueueManager>MAO1</ReplyQueueManager> 
         <RequestQueue>GSTAR.ICS.DP.DHIPO211.REQUEST</RequestQueue> 
         <ReplyQueue>ICS.DP.REPLY</ReplyQueue> 
        </QueueDetails> 

       </SORRegion> 
       <SORRegion name="default"> 
        <ConsumerName name="MYCA"> 
         <AutomationIds> 
          <PreAutoId> 
           <AutomationId>XA1146A</AutomationId> 
           <AutomationId>XA1146A</AutomationId> 
          </PreAutoId> 
          <DefaultAutoId> 
           <AutomationId>XA1146A</AutomationId> 
          </DefaultAutoId> 
         </AutomationIds> 
        </ConsumerName> 
        <QueueDetails> 
         <QueueManager>MAO1</QueueManager> 
         <ReplyQueueManager>MAO1</ReplyQueueManager> 
         <RequestQueue>DEFAULT.REQUEST</RequestQueue> 
         <ReplyQueue>ICS.DP.REPLY</ReplyQueue> 
        </QueueDetails> 

       </SORRegion> 
      </CountryCode> 
     </SOR> 
    </Service> 
</RoutingDetails> 

वास्तव में चाहता था, सही परिणाम का उत्पादन

संबंधित मुद्दे