xsl-list
[Top] [All Lists]

RE: [xsl] Pattern Matching in XSl - find groups defined in one Xml in another Xml.

2012-08-29 11:28:43
At 2012-08-29 16:16 +0000, Kerry, Richard wrote:
Regarding Ken's solutions from last Wednesday (repeated below), why is it :

<xsl:analyze-string select="$thisAlarm/@equipment" regex="^{$thisGroupedAlarm/@equipment}$">
<xsl:matching-substring>
<xsl:for-each select="regex-group(1)[normalize-space(.)]">
<xsl:attribute name="found-key" select="."/>
</xsl:for-each>
</xsl:matching-substring>
</xsl:analyze-string>

rather than

<xsl:analyze-string select="$thisAlarm/@equipment" regex="^{$thisGroupedAlarm/@equipment}$">
<xsl:matching-substring>
<xsl:attribute name="found-key" select="regex-group(1)"/>
</xsl:matching-substring>
</xsl:analyze-string>

?

What does the [normalize-space(.)] predicate do for us ?

I am positioning the context to be the regex-group(1) string only if that string is non-empty (or, at least, not made entirely of white-space characters; if you want found white-space preserved, then replace normalize-space(.) with string(.) instead). If the string is empty, then I don't want to create the attribute. If the string is non empty, then I want to create the attribute with that string value, which is now the context.

In your example, matching "1 Alarm" that does not have any groups will create the empty attribute found-key="" ... which wasn't in your example of what you wanted. I understood you to want found-key= suppressed if there were no search strings in the content.

So your suggested code will create the empty found-key="" and mine will not.

I hope this is helpful.

. . . . . . . . . . Ken


--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>