हां।
मैं यह XSLT 1.0 परिवर्तन:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ext="http://exslt.org/common"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vrtfPass1">
<xsl:apply-templates/>
</xsl:variable>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*" mode="pass2">
<xsl:copy>
<xsl:apply-templates select="node()|@*" mode="pass2"/>
</xsl:copy>
</xsl:template>
<xsl:template match="num/text()">
<xsl:value-of select="2*."/>
</xsl:template>
<xsl:template match="num/text()" mode="pass2">
<xsl:value-of select="1+."/>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="ext:node-set($vrtfPass1)/*" mode="pass2"/>
</xsl:template>
</xsl:stylesheet>
जब इस XML दस्तावेज़ पर लागू:
<t>
<num>1</num>
<num>2</num>
<num>3</num>
<num>4</num>
<num>5</num>
</t>
पैदा करता है:
<t>
<num>3</num>
<num>5</num>
<num>7</num>
<num>9</num>
<num>11</num>
</t>
ध्यान दें करो:
दो परिवर्तनों वास्तव में प्रदर्शन कर रहे हैं, दूसरी पहले के परिणाम पर किया जाता है।
पहले परिवर्तन का परिणाम परिवर्तनीय $vrtfPass1
की सामग्री है।
XSLT 1.0 चर के प्रकार है कि गतिशील रूप से (अस्थायी) एक्सएमएल पेड़ (XML दस्तावेज़ या XML टुकड़ा) उत्पन्न होते हैं में आरटीएफ (परिणाम-ट्री-टुकड़ा) है। आरटीएफ पर कोई XPath ऑपरेशंस संभव नहीं है - इसे एक्सटेंशन फंक्शन xxx:node-set()
का उपयोग करके नियमित नोड-सेट में परिवर्तित करने की आवश्यकता है, जो एक्सएसएलटी 1.0 प्रोसेसर विक्रेताओं के विशाल बहुमत द्वारा प्रदान की जाती है। इस उदाहरण में exslt: नोड-सेट() का उपयोग किया जाता है, क्योंकि EXSLT कई अलग-अलग विक्रेताओं द्वारा कार्यान्वित किया जाता है।
दूसरा परिवर्तन पहले: <xsl:apply-templates select="ext:node-set($vrtfPass1)/*" mode="pass2"/>
के परिणाम पर लागू होता है। एक अलग mode
का उपयोग दो परिवर्तनों के कोड को साफ़ करने के लिए किया जाता है।
पहला रूपांतरण प्रत्येक num/text()
2 से गुणा करता है। दूसरा परिवर्तन प्रत्येक num/text()
में वृद्धि करता है। परिणाम 2*.+1
द्वितीय है। यह XSLT 2.0 परिवर्तन:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vPass1">
<xsl:apply-templates mode="pass1"/>
</xsl:variable>
<xsl:template match="node()|@*" mode="pass1">
<xsl:copy>
<xsl:apply-templates select="node()|@*" mode="pass1"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*" mode="pass2">
<xsl:copy>
<xsl:apply-templates select="node()|@*" mode="pass2"/>
</xsl:copy>
</xsl:template>
<xsl:template match="num/text()" mode="pass1">
<xsl:value-of select="2*xs:integer(.)"/>
</xsl:template>
<xsl:template match="num/text()" mode="pass2">
<xsl:value-of select="1+."/>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="$vPass1" mode="pass2"/>
</xsl:template>
</xsl:stylesheet>
जब एक ही XML दस्तावेज़ पर लागू किया, एक ही चाहता था और सही परिणाम पैदा करता है।
नोट: एक्सएसएलटी 2.0/XPath 2.0 में आरटीएफ प्रकार समाप्त कर दिया गया है। नहीं xxx:node-set()
एक्सटेंशन फ़ंक्शन की आवश्यकता है।
स्रोत
2010-09-09 16:57:48
क्या आप चाहते हैं कि दो परिवर्तन एक पास में हों? और यदि हां, तो मध्य आदमी को क्यों न हटाएं और सीधे अपने इच्छित आउटपुट में परिवर्तित हो जाएं? – recursive
आपको एक एक्सएसएलटी के साथ ऐसा करने की आवश्यकता क्यों है? दो अलग फाइलें क्यों नहीं हैं? –
मेरे पास एक ऐप है जो केवल एक एक्सएसएलटी फाइल स्वीकार करता है लेकिन मैं दूसरी ट्रांसफॉर्म फ़ाइल में दूसरे ट्रांसफॉर्म को लागू करना चाहता हूं। – koumides