检测XML字段中的URL
XSLT是否可以通过脚本或其他方式检测以下情况之一:检测XML字段中的URL,xml,xslt,hyperlink,detection,Xml,Xslt,Hyperlink,Detection,XSLT是否可以通过脚本或其他方式检测以下情况之一: "http://..." 或 “http…” 在消息字段中,并将其样式设置为链接。我做好了最坏的打算 XPath2.0提供了正则表达式处理的宝贵功能。 在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
"http://..."
或
“http…”
在消息字段中,并将其样式设置为链接。我做好了最坏的打算 XPath2.0提供了正则表达式处理的宝贵功能。 在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="vurlRegex"
>(http|https|ftp|mailto)://(\p{L}+\.)+\p{L}+(/\p{L}([./?%&=])*)?</xsl:variable>
<xsl:template match="/*/*[not(matches(.,$vurlRegex))]">
<xsl:sequence select='"Warning:", ., " isn't a valid Uri
"'/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
Warning:<b>\`\```^^^</b> isn't a valid Uri
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="my:my">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vurlRegex"
>((([A-Za-z])[A-Za-z0-9+\-\.]*)
:((//(((([A-Za-z0-9\-\._~!$&'()*+,;=:]|(%[0-9A-Fa-f][0-9A-Fa-f]))*@))?
((\[(((((([0-9A-Fa-f]){0,4}:)){6}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5])))))
|(::((([0-9A-Fa-f]){0,4}:)){5}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))))
|((([0-9A-Fa-f]){0,4})?::((([0-9A-Fa-f]){0,4}:)){4}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5])))))|(((((([0-9A-Fa-f]){0,4}:))?([0-9A-Fa-f]){0,4}))?::((([0-9A-Fa-f]){0,4}:)){3}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5])))))|(((((([0-9A-Fa-f]){0,4}:)){0,2}([0-9A-Fa-f]){0,4}))?
::((([0-9A-Fa-f]){0,4}:)){2}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})|
(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|
([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5])))))|(((((([0-9A-Fa-f]){0,4}:)){0,3}([0-9A-Fa-f]){0,4}))
?::([0-9A-Fa-f]){0,4}:((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})|(([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))))
|(((((([0-9A-Fa-f]){0,4}:)){0,4}([0-9A-Fa-f]){0,4}))?::((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))))
|(((((([0-9A-Fa-f]){0,4}:)){0,5}([0-9A-Fa-f]){0,4}))?::([0-9A-Fa-f]){0,4})
|(((((([0-9A-Fa-f]){0,4}:)){0,6}([0-9A-Fa-f]){0,4}))?::))|(v([0-9A-Fa-f])+\.(([A-Za-z0-9\-\._~]
|[!$&'()*+,;=]|:))+))\])|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))|(([A-Za-z0-9\-\._~]|(%[0-9A-Fa-f][0-9A-Fa-f])
|[!$&'()*+,;=]))*)((:([0-9])*))?)((/(([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))*))*)
|(/(((([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))+((/(([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))*))*))?)
|((([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))+((/(([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))*))*)
|)((\?((([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f]))|/
|\?))*))?((#((([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f]))|/|\?))*))?)</xsl:variable>
<xsl:template match="/*/*[not(my:IsValidUrl(.))]">
<xsl:sequence select='"Warning:", ., " isn't a valid Uri
"'/>
</xsl:template>
<xsl:template match="text()"/>
<xsl:function name="my:IsValidUrl" as="xs:boolean">
<xsl:param name="pStr" as="xs:string"/>
<xsl:sequence select="matches($pStr, $vurlRegex, 'x')"/>
</xsl:function>
</xsl:stylesheet>
更新:
<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="vurlRegex"
>(http|https|ftp|mailto)://(\p{L}+\.)+\p{L}+(/\p{L}([./?%&=])*)?</xsl:variable>
<xsl:template match="/*/*[not(matches(.,$vurlRegex))]">
<xsl:sequence select='"Warning:", ., " isn't a valid Uri
"'/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
Warning:<b>\`\```^^^</b> isn't a valid Uri
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="my:my">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vurlRegex"
>((([A-Za-z])[A-Za-z0-9+\-\.]*)
:((//(((([A-Za-z0-9\-\._~!$&'()*+,;=:]|(%[0-9A-Fa-f][0-9A-Fa-f]))*@))?
((\[(((((([0-9A-Fa-f]){0,4}:)){6}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5])))))
|(::((([0-9A-Fa-f]){0,4}:)){5}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))))
|((([0-9A-Fa-f]){0,4})?::((([0-9A-Fa-f]){0,4}:)){4}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5])))))|(((((([0-9A-Fa-f]){0,4}:))?([0-9A-Fa-f]){0,4}))?::((([0-9A-Fa-f]){0,4}:)){3}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5])))))|(((((([0-9A-Fa-f]){0,4}:)){0,2}([0-9A-Fa-f]){0,4}))?
::((([0-9A-Fa-f]){0,4}:)){2}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})|
(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|
([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5])))))|(((((([0-9A-Fa-f]){0,4}:)){0,3}([0-9A-Fa-f]){0,4}))
?::([0-9A-Fa-f]){0,4}:((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})|(([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))))
|(((((([0-9A-Fa-f]){0,4}:)){0,4}([0-9A-Fa-f]){0,4}))?::((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))))
|(((((([0-9A-Fa-f]){0,4}:)){0,5}([0-9A-Fa-f]){0,4}))?::([0-9A-Fa-f]){0,4})
|(((((([0-9A-Fa-f]){0,4}:)){0,6}([0-9A-Fa-f]){0,4}))?::))|(v([0-9A-Fa-f])+\.(([A-Za-z0-9\-\._~]
|[!$&'()*+,;=]|:))+))\])|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))|(([A-Za-z0-9\-\._~]|(%[0-9A-Fa-f][0-9A-Fa-f])
|[!$&'()*+,;=]))*)((:([0-9])*))?)((/(([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))*))*)
|(/(((([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))+((/(([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))*))*))?)
|((([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))+((/(([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))*))*)
|)((\?((([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f]))|/
|\?))*))?((#((([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f]))|/|\?))*))?)</xsl:variable>
<xsl:template match="/*/*[not(my:IsValidUrl(.))]">
<xsl:sequence select='"Warning:", ., " isn't a valid Uri
"'/>
</xsl:template>
<xsl:template match="text()"/>
<xsl:function name="my:IsValidUrl" as="xs:boolean">
<xsl:param name="pStr" as="xs:string"/>
<xsl:sequence select="matches($pStr, $vurlRegex, 'x')"/>
</xsl:function>
</xsl:stylesheet>
这里我使用了迈克尔·凯(Michael Kay)在其评论中提供的表达参考——这是:
<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="vurlRegex"
>(http|https|ftp|mailto)://(\p{L}+\.)+\p{L}+(/\p{L}([./?%&=])*)?</xsl:variable>
<xsl:template match="/*/*[not(matches(.,$vurlRegex))]">
<xsl:sequence select='"Warning:", ., " isn't a valid Uri
"'/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
Warning:<b>\`\```^^^</b> isn't a valid Uri
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="my:my">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vurlRegex"
>((([A-Za-z])[A-Za-z0-9+\-\.]*)
:((//(((([A-Za-z0-9\-\._~!$&'()*+,;=:]|(%[0-9A-Fa-f][0-9A-Fa-f]))*@))?
((\[(((((([0-9A-Fa-f]){0,4}:)){6}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5])))))
|(::((([0-9A-Fa-f]){0,4}:)){5}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))))
|((([0-9A-Fa-f]){0,4})?::((([0-9A-Fa-f]){0,4}:)){4}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5])))))|(((((([0-9A-Fa-f]){0,4}:))?([0-9A-Fa-f]){0,4}))?::((([0-9A-Fa-f]){0,4}:)){3}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5])))))|(((((([0-9A-Fa-f]){0,4}:)){0,2}([0-9A-Fa-f]){0,4}))?
::((([0-9A-Fa-f]){0,4}:)){2}((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})|
(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|
([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5])))))|(((((([0-9A-Fa-f]){0,4}:)){0,3}([0-9A-Fa-f]){0,4}))
?::([0-9A-Fa-f]){0,4}:((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})|(([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))))
|(((((([0-9A-Fa-f]){0,4}:)){0,4}([0-9A-Fa-f]){0,4}))?::((([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))))
|(((((([0-9A-Fa-f]){0,4}:)){0,5}([0-9A-Fa-f]){0,4}))?::([0-9A-Fa-f]){0,4})
|(((((([0-9A-Fa-f]){0,4}:)){0,6}([0-9A-Fa-f]){0,4}))?::))|(v([0-9A-Fa-f])+\.(([A-Za-z0-9\-\._~]
|[!$&'()*+,;=]|:))+))\])|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))|(([A-Za-z0-9\-\._~]|(%[0-9A-Fa-f][0-9A-Fa-f])
|[!$&'()*+,;=]))*)((:([0-9])*))?)((/(([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))*))*)
|(/(((([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))+((/(([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))*))*))?)
|((([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))+((/(([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f])))*))*)
|)((\?((([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f]))|/
|\?))*))?((#((([A-Za-z0-9\-\._~!$&'()*+,;=:@]|(%[0-9A-Fa-f][0-9A-Fa-f]))|/|\?))*))?)</xsl:variable>
<xsl:template match="/*/*[not(my:IsValidUrl(.))]">
<xsl:sequence select='"Warning:", ., " isn't a valid Uri
"'/>
</xsl:template>
<xsl:template match="text()"/>
<xsl:function name="my:IsValidUrl" as="xs:boolean">
<xsl:param name="pStr" as="xs:string"/>
<xsl:sequence select="matches($pStr, $vurlRegex, 'x')"/>
</xsl:function>
</xsl:stylesheet>
([A-Za-z])[A-Za-z0-9+\-\.]*)
:(/(([A-Za-z0-9\-\.!$&;'()*+,;=:]|([0-9A-Fa-f][0-9A-Fa-f])*)?
(\[(((([0-9A-Fa-f]){0,4}:){6}(([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5])))))
|(::(([0-9A-Fa-f]){0,4}:){5}(([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))))
|((([0-9A-Fa-f]){0,4})::(([0-9A-Fa-f]){0,4}:){4}(([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5]()(((((((()0-9A-Fa-f){0,4})((((0-9A-Fa-f){0,4})):((0-9A-Fa
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5])|((((([0-9A-Fa-f]){0,4}:){0,2}([0-9A-Fa-f]){0,4})?
:(([0-9A-Fa-f]){0,4}:){2}(([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})|
(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|
([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5])|((((([0-9A-Fa-f]){0,4}:){0,3}([0-9A-Fa-f]){0,4}))
([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})([0-9]|([1-9][0-9]))
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])
|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))))
|(((([0-9A-Fa-f]){0,4}:){0,4}([0-9A-Fa-f]){0,4}):(([0-9A-Fa-f]){0,4}:([0-9A-Fa-f]){0,4})
|(([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})
|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5])))))
|(((([0-9A-Fa-f]){0,4}:){0,5}([0-9A-Fa-f]){0,4}))?:([0-9A-Fa-f]){0,4})
|(([0-9A-Fa-f]){0,4}:){0,6}([0-9A-Fa-f]){0,4})?:)|(v([0-9A-Fa-f])+\([A-Za-z0-9\-\.]
|[0-9][1-9][0-9][0-9][2}(2[0-4][0-9])(25[0-5])\([0-9][0-9])
|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]|([1-9][0-9])|(1([0-9]){2})|(2[0-4][0-9])|(25[0-5]))\.([0-9]
|([1-9][0-9])|(1[0-9]){2}(2[0-4][0-9])|(25[0-5])|([A-Za-z0-9\-\.\.\.[0-9A-Fa-f][0-9A-Fa-f]))
|((:([0-9])*)?(/([A-Za-z0-9\-\.\uz0-9\-\.-)*+,;=:@]。([0-9A-Fa-f][0-9A-Fa-f])*)*)
|(/(([A-Za-z0-9\-\.!$)([0-9A-Fa-f][0-9A-Fa-f])+(([A-Za-z0-9\-\.!$)(*+,;=:@]([0-9A-Fa-f][0-9A-Fa-f]))*)
|(([A-Za-z0-9\-\.\.!$&;'()*+,;=:@]([0-9A-Fa-f][0-9A-Fa-f]))+((/([A-Za-z0-9\-\.!'()*+,=:@]|([0-9A-Fa-f][0-9A-Fa-f]))*)
|)((\?([A-Za-z0-9\-\.!$&;'()*+,;=:@]。([0-9A-Fa-f][0-9A-Fa-f]))|/
|\(([A-Za-z0-9\-\.[A-Za-z0-9\-\.\.!$&;'()*+,;=:@]。([0-9A-Fa-f][0-9A-Fa-f]))/?)
请不要只要求我们为您解决问题。向我们展示你是如何试图自己解决问题的,然后向我们展示结果是什么,并告诉我们为什么你觉得它不起作用。请参阅“”,这是一篇您确实需要阅读的优秀文章。在本例中,作者每行解析文本行,并使用substring after和substring before可能会有所帮助。我在一篇不相关的文章中发现,XSLT既不处理“detect&format”,也不直接处理XML。最好的解决方案似乎是使用javascript函数之类的东西处理源XML文件。我想我期待XSLT成为XML的灵丹妙药。@Pres,关于你最后的评论:看来你还没有读到我的答案:)@Dimitre。非常感谢你的回答。我不在家,我认为这一评论是在你作出深入回应之前发表的。我刚刚看到了这一点,所以将在第一个可能的机会阅读。感谢您提供如此明确的答案。我只使用了XSLT v1,因此必须尽快深入研究v2,如果您想要更精确的正则表达式,这里有一个:,尽管它非常长,并且不能保证它不会破坏一些正则表达式引擎。(还有一个变体位于./TypeLibrary-IRI-RFC3987.xsd)@MichaelKay,谢谢。一个相关的问题——为什么不能使用xs:anyUri
验证?我尝试将castable设置为
和实例
——结果就像我指定了xs:string
基本上,XSD在URI的定义上陷入了混乱。有太多的定义:绝对URI、相对URI、遗留URI(leiris)、“wannabe URI”(在%-编码后的URI字符串)URI符合通用语法,但不符合