31. marts 2008 - 12:52
Der er
10 kommentarer og 2 løsninger
replace hvordan?
Jeg har noget der bliver udskrevet her: <xsl:apply-templates select="/OrderHandbook/CompanyCategories"/> Jeg vil gerne have tegnet "#" bliver erstattet med ingenting - fx så: hej# bare bliver til hej
Annonceindlæg fra DE-CIX
31. marts 2008 - 13:52
#1
<xsl:template name="StrSplit"> <xsl:param name="str" /> <xsl:choose> <xsl:when test="contains($str,'=')"> <xsl:attribute name="{normalize-space(substring-before($str,'='))}"> <xsl:value-of select="substring-before(substring-after($str,'"'),'"')" /> </xsl:attribute> <xsl:call-template name="StrSplit"> <xsl:with-param name="str" select="substring-after(substring-after($str,'"'),'"')" /> </xsl:call-template> </xsl:when> </xsl:choose> </xsl:template> Brug den :) /JJ
31. marts 2008 - 13:53
#2
how vent.. den er ikke så dynamisk..
31. marts 2008 - 13:54
#3
<!-- reusable replace-string function --> <xsl:template name="replace-string"> <xsl:param name="text"/> <xsl:param name="from"/> <xsl:param name="to"/> <xsl:choose> <xsl:when test="contains($text, $from)"> <xsl:variable name="before" select="substring-before($text, $from)"/> <xsl:variable name="after" select="substring-after($text, $from)"/> <xsl:variable name="prefix" select="concat($before, $to)"/> <xsl:value-of select="$before"/> <xsl:value-of select="$to"/> <xsl:call-template name="replace-string"> <xsl:with-param name="text" select="$after"/> <xsl:with-param name="from" select="$from"/> <xsl:with-param name="to" select="$to"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$text"/> </xsl:otherwise> </xsl:choose> </xsl:template>
31. marts 2008 - 13:55
#4
brug så: <xsl:call-template name="replace-string"> <xsl:with-param name="text" select="'hej#'" /> <xsl:with-param name="to" select="''" /> <xsl:with-param name="from" select="'#'" /> </>
31. marts 2008 - 14:09
#5
Altså har dette : <xsl:template match="CompanyCategories"> <select name="CompanyCategory" style="width: 152px;" onchange="java script:GetValue(this.options[this.options.selectedIndex].value)"> <option value=""> <xsl:value-of select="/OrderHandbook/Labels/Choose"/> </option> <xsl:for-each select="node()"> <option value="{.}"> <xsl:value-of select="."/> </option> </xsl:for-each> </select> <br/> </xsl:template> Hvordan skal jeg bruge replace på det ?
31. marts 2008 - 14:34
#6
<xsl:template match="CompanyCategories"> <select name="CompanyCategory" style="width: 152px;" onchange="java script:GetValue(this.options[this.options.selectedIndex].value)"> <option value=""> <xsl:call-template name="replace-string"> <xsl:with-param name="text" select="/OrderHandbook/Labels/Choose" /> <xsl:with-param name="to" select="''" /> <xsl:with-param name="from" select="'#'" /> </xsl:call-template> </option> <xsl:for-each select="node()"> <option value="{.}"> <xsl:value-of select="."/> </option> </xsl:for-each> </select> <br/> </xsl:template>
31. marts 2008 - 14:40
#7
Hmm, det fungerer ikke helt, den udskriver stadig havelågen... <xsl:template match="CompanyCategories"> <select name="CompanyCategory" style="width: 152px;" onchange="java script:GetValue(this.options[this.options.selectedIndex].value)"> <option value=""> <xsl:call-template name="replace-string"> <xsl:with-param name="text" select="/OrderHandbook/Labels/Choose" /> <xsl:with-param name="to" select="''" /> <xsl:with-param name="from" select="'#'" /> </xsl:call-template> </option> <xsl:for-each select="node()"> <option value="{.}"> <xsl:value-of select="."/> </option> </xsl:for-each> </select> <br/> </xsl:template> <xsl:template name="replace-string"> <xsl:param name="text"/> <xsl:param name="from"/> <xsl:param name="to"/> <xsl:choose> <xsl:when test="contains($text, $from)"> <xsl:variable name="before" select="substring-before($text, $from)"/> <xsl:variable name="after" select="substring-after($text, $from)"/> <xsl:variable name="prefix" select="concat($before, $to)"/> <xsl:value-of select="$before"/> <xsl:value-of select="$to"/> <xsl:call-template name="replace-string"> <xsl:with-param name="text" select="$after"/> <xsl:with-param name="from" select="$from"/> <xsl:with-param name="to" select="$to"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$text"/> </xsl:otherwise> </xsl:choose> </xsl:template>
31. marts 2008 - 14:45
#8
Så er det fordi den ikke kan se tegnet, er du sikker på det ikke er htmlencoded i dit output ? Virker det her heller ikke ? <xsl:call-template name="replace-string"> <xsl:with-param name="text" select="'hej#'" /> <xsl:with-param name="to" select="''" /> <xsl:with-param name="from" select="'#'" /> </call-template> /JJ
31. marts 2008 - 14:52
#9
Nej, altså tegn som fx ">" bliver udskrevet som >
31. marts 2008 - 15:13
#10
og det er tegnet # du forsøger med ? # er det samme html/url encoded.. /JJ
31. marts 2008 - 15:17
#11
Ok, det forstod jeg ik noget af :) - skal jeg i stedet for # bruger ascii tegn for at finde frem til tegnet?
31. marts 2008 - 15:20
#12
der er ingen alternativer til #... Virker det her? <xsl:call-template name="replace-string"> <xsl:with-param name="text" select="'hej'" /> <xsl:with-param name="to" select="'hej med dig'" /> <xsl:with-param name="from" select="'hej'" /> </call-template> ??? /JJ
Kurser inden for grundlæggende programmering