XSLT

2010-06-07 13 views
7

XSLT

के साथ एक एकल विशेषता परिवर्तन क्या सरलतम XSLT आप सोच सकते हैं मूल्य पहले से ही विशेषता true से false को बदलने के लिए, इस मामले में, /configuration/system.web/compilation/@debug है?

+0

अच्छा प्रश्न (+1)। एक संक्षिप्त, सरल और सही समाधान के लिए मेरा जवाब देखें। वर्तमान में लुसेरो का जवाब काफी गलत है - मेरे जवाब पर मेरी टिप्पणी देखें। –

उत्तर

6

यह परिवर्तन:

<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()|@*" name="identity"> 
    <xsl:copy> 
    <xsl:apply-templates select="node()|@*"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="system.web/compilation[1]/@debug"> 
    <xsl:attribute name="debug">false</xsl:attribute> 
</xsl:template> 
</xsl:stylesheet> 

जब इस XML दस्तावेज़ पर लागू: को संशोधित करता है पहले compilation बच्चे की debug विशेषता:

<configuration> 
    <system.web> 
     <compilation debug="true" defaultLanguage="C#"> 
      <!-- this is a comment --> 
     </compilation> 

     <compilation debug="true" defaultLanguage="C#"> 
      <!-- this is another comment --> 
     </compilation> 
    </system.web> 
</configuration> 

चाहता था, सही परिणाम का उत्पादन किसी भी system.web तत्व (लेकिन हम जानते हैं कि चालू है एक कॉन्फ़िगरेशन फ़ाइल में एक system.web तत्व ly।

<configuration> 
    <system.web> 
     <compilation debug="false" defaultLanguage="C#"> 
      <!-- this is a comment --> 
     </compilation> 
     <compilation debug="true" defaultLanguage="C#"> 
      <!-- this is another comment --> 
     </compilation> 
    </system.web> 
</configuration> 

हम देखते हैं के रूप में, केवल पहले debug गुण, false को modifird के रूप में आवश्यक है।

+1

इसे एक्सएसएलटी के लिए पहचान पैटर्न बदलने के लिए कहा जाता है, और @Dimitre Novatchev ने बताया, यह बेहद शक्तिशाली है। – lavinio

+0

यह एक शर्म की बात है कि 'xsl: विशेषता' तत्व को विशेषता के नाम का उल्लेख करना होगा, जब इसे पहले से ही XPath में दिया गया है जो 'xsl: template' मिलान संलग्न है। क्या यह कहने का कोई तरीका है "इस विशेषता को सेट करें, जिसे भी कहा जाता है"? –

+0

@ टॉम एंडरसन: कोई एवीटी नोटेशन का उपयोग कर सकता है: '' यह वही नहीं है जो आप चाहते हैं लेकिन कुछ सम्मान में भी बेहतर है। –

-1

<xsl:attribute name="debug">false</xsl:attribute><compilation> के अंदर? या क्या मैं इस सवाल को गलत समझ रहा हूं?