मेरे लिए सबसे अच्छा काम करना समाप्त हुआ था आने वाले दस्तावेज़ पर एक्सएसएलटी का उपयोग करके इन्हें दोबारा बचाना था (और आउटगोइंग दस्तावेज़ पर इसे उलटाना)।
तो <
एक विशेषता में &lt;
बन जाता है। सुझाव के लिए @Abel के लिए धन्यवाद।
यहाँ, XSLT मैं जोड़ा है मामले में अन्य लोगों ने इसे उपयोगी पाते:
पहले XSLT 1.0 में स्ट्रिंग प्रतिस्थापन करने के लिए एक टेम्पलेट है। यदि आप एक्सएसएलटी 2.0 का उपयोग कर सकते हैं, तो आप इसके बजाय निर्मित replace
का उपयोग कर सकते हैं।
<!-- xml -> html -->
<xsl:template name="replace-html-codes">
<xsl:param name="text"/>
<xsl:variable name="lt">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$text"/>
<xsl:with-param name="replace" select="'<'"/>
<xsl:with-param name="by" select="'&lt;'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="gt">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$lt"/>
<xsl:with-param name="replace" select="'>'"/>
<xsl:with-param name="by" select="'&gt;'"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$gt"/>
</xsl:template>
<!-- html -> xml -->
<xsl:template name="restore-html-codes">
<xsl:param name="text"/>
<xsl:variable name="lt">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$text"/>
<xsl:with-param name="replace" select="'&lt;'"/>
<xsl:with-param name="by" select="'<'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="gt">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$lt"/>
<xsl:with-param name="replace" select="'&gt;'"/>
<xsl:with-param name="by" select="'>'"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$gt"/>
</xsl:template>
XSLT ज्यादातर एक पास के माध्यम से है:
<xsl:template name="string-replace-all">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by" select="$by"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
अगला कि विशिष्ट प्रतिस्थापन है कि मैं की आवश्यकता है टेम्पलेट है। मैं तो बस जब नकल विशेषताओं का उचित टेम्पलेट फोन: मैं jQuery के `.html()` का उपयोग कर रहा
<xsl:template match="@*">
<xsl:attribute name="data-{local-name()}">
<xsl:call-template name="replace-html-codes">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:attribute>
</xsl:template>
<!-- copy all nodes -->
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
@Abel, मैं सिर्फ मैं कहाँ लगता है "समस्या" हो रहा है करने के लिए नीचे कम करने के लिए प्रयास किया। स्रोत दस्तावेज़ एक्सएमएल है, जिसे मैं '.html() 'के साथ डालने से पहले ब्राउज़र XSLT के माध्यम से चलाता हूं। बाद में मैं एक्सएमएल को वापस पाने के लिए इसे उलटा प्रक्रिया के माध्यम से ले जाता हूं। मुझे बस यह अजीब लगता है कि डोम * इस चरित्र को अनदेखा कर रहा है (और दूसरों को नहीं)। – murrayju
मैं स्रोत एक्सएमएल को संशोधित नहीं कर सकता, और अंत में आउटपुट में एक ही सामग्री को संरक्षित करने की आवश्यकता है।मैं बीच में जो भी परिवर्तन आवश्यक हो सकता हूं, लेकिन कुछ रेगेक्स प्रतिस्थापन से बेहतर करने के लिए एक तरीका तलाश रहा हूं। विशेष रूप से चरित्र पर विचार करना '<' है, जिसे दस्तावेज़ भरा हुआ है। – murrayju
@ अब्बल मेरा एकमात्र लक्ष्य यह है कि इसे डीओएम से वापस ले जाना उसी तरह से (जैसा कि < ') था। मैं इसे '.text (स्ट्रिंग)' के साथ डाल रहा हूं और इसे '.text()' के साथ प्राप्त कर रहा हूं। इस राउंड-ट्रिप के साथ मेरी समस्या यह है कि इनपुट आउटपुट के बराबर नहीं है (केवल इस मामले में)। – murrayju