|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Catch a Character ...Hello everyone,
I am trying to catch a special character with the following style sheet: <xsl:param name="specChar" select="'\u201C'" /> <xsl:output indent="yes" method="xml"/> <xsl:strip-space elements="*"/> <xsl:template match="CATALOOM-OPENENGINE/PRODUCTS/PRODUCT/PRODUCTREVISION"> <xsl:variable name="primKey2"> <xsl:value-of select="substring-before(@primarykey, '/')"/> </xsl:variable> <xsl:for-each select="FEATURE/VALUE"> <xsl:variable name="cdata"> <xsl:value-of select="FEATURE/VALUE/text()"/> </xsl:variable> <xsl:if test="contains($cdata, $specChar)"> <xsl:text>Found: </xsl:text> <xsl:value-of select="$primKey2" /> <xsl:text> </xsl:text> </xsl:if> </xsl:for-each> </xsl:template> I am not getting any hits, though there should be a couple of thousands. A few questions: Is there anything overly wrong with this stylesheet? The XML is like <PRODUCTREVISION> <FEATURE><VALUE>...</VALUE></FEATURE> </PRODUCTREVISION> How do I have to mask a unicode char inside a string inside a stylesheet? |
|
|
Re: Catch a Character ...Claus Kick schrieb:
> > I am trying to catch a special character with the following style sheet: > > <xsl:param name="specChar" select="'\u201C'" /> That's the Java syntax. Doesn't work in XML. Use a numerical character reference as per the XML spec. <xsl:param name="specChar" select="'“'" /> in hex, or <xsl:param name="specChar" select="'“'" /> in decimal > <xsl:output indent="yes" method="xml"/> > <xsl:strip-space elements="*"/> > > <xsl:template > match="CATALOOM-OPENENGINE/PRODUCTS/PRODUCT/PRODUCTREVISION"> Not knowing your input, I can't be sure, but simply doing match="PRODUCTREVISION" would probably be specific enough. > <xsl:variable name="primKey2"> > <xsl:value-of select="substring-before(@primarykey, '/')"/> > </xsl:variable> That's a very bad way of getting the value. Instead, use: <xsl:variable name="primKey2" select="substring-before(@primarykey, '/')"/> Your version creates a so-called "result tree fragment" (RTF), which is inefficient and cumbersome. > <xsl:for-each select="FEATURE/VALUE"> > <xsl:variable name="cdata"> > <xsl:value-of select="FEATURE/VALUE/text()"/> > </xsl:variable> Same story here. In addition, avoid using the text() node test to get the string value: <xsl:value-of select="FEATURE/VALUE"/> But are you sure your input is FEATURE/VALUE/FEATURE/VALUE? > How do I have to mask a unicode char inside a string inside a > stylesheet? As shown above. Or simply as a literal, if you're using a Unicode encoding and your input device and display support that character. You can learn XSLT by reading XSL-List at Mulberrytech or any good book in XSLT, like, for starters, the Pocket Guide by Evan Lenz. -- Michael Ludwig |
|
|
|
|
|
Re: Catch a Character ...2009/9/22 Michael Ludwig <mlu@...>
Claus Kick schrieb: Hello Michael, thanks for reminding me (yet again - sigh) to include the group. Thanks for your help - regarding Xalan or not: We have Xalan in use in a huge amount of different places (data storage/exchange platform) and I currently dread to even think about switching. Currently, there is simply no way I could ensure that no breakage happens. |
| Free embeddable forum powered by Nabble | Forum Help |