I'd like to use regular expressions in selecting elements using the match function. I'd prefer not to use an external library (such as saxon) to do this.
相关问题
- Illegal to have multiple roots (start tag in epilo
- Newtonsoft DeserializeXNode expands internal array
- how to use special characters like '<'
- XPath How to retrieve the value of a table cell fr
- XML - XSLT - document() function inside count() fu
相关文章
- scrapy爬虫数据清洗
- Creating XML Elements without namespace declaratio
- Get Attribute Value From Simple XML Using JQuery /
- Directly signing an Office Word document using XML
- When sending XML to JMS should I use TextMessage o
- Fragment Content Overlaps Toolbar and Bottom Navig
- Getting “Error: Missing Constraints in ConstraintL
- xslt localization
For future reference, here's a nice page on extending xpath/xquery in .net:
http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=64
I don't trust this to last, so I copy it here:
XSLT is a transformation language for XML. It allows server systems to transform the source XML tree into a more suitable form for clients. XSLT uses node patterns to match against templates to perform its transformations. Though it makes complex transformations relatively simple there are some situations where we might have to use some custom classes.
Some of the situations where we might need to extend XSLT are:
1) Call custom business logic
2) Perform different actions depending on Permissions
3) Perform complex formatting for dates, strings etc
4) Or even call a webservice!!
Steps to extend XSLT
1) Create the custom object to use from within XSLT(in C#)
2) Provide a custom namespace declaration for the custom class within XSLTs namespace declaration(in XSLT file)
3) Pass an instance of the custom object to XSLT, with the same namespace as in last step(in C#)
4) Use the object from within XSLT(in XSLT file)
Sample code
For our example let us assume we have a XSLT sheet where we need to manipulate dates. We need to show the number of days the employee has been with the company. Since XSLT has no native date manipulation functions, let us use an extension object for our task.
Compile this code and use the provided members.xml and memberdisplay.xsl to run this console application. You should see a extendXSLT.html file within the same folder. Open this file and notice that our class CustomDate has been called to calculate the number of days the employee has been in the company.
Summary :
XSLT is a powerfull transformation language for XML, however using extension objects in .NET and C# should ensure that we could easily accomplish what would be impossible or hard with XSLT alone.
Members.xml:
Memberdisplay.xsl:
When discussing .NET support for XSLT 2.0, XPath 2.0, and XQuery 1.0, it is important to distinguish between the languages themselves and the Data Model (XDM). The .NET 3.5 Framework supports the Data Model, but not the languages. As it was recently explained to me via email correspondence by Microsoft's Pawel Kadluczka:
I believe the answer in this discussion is misleading. I think .NET 3.5 doesn't support most XSL/T 2.0 functions (if any at all).
An example:
A call to a 2.0 function gives the following error message under .NET 3.5:
'current-dateTime()' is an unknown XSLT function.
I think the answer above is wrong. I can't find any evidence that Microsoft supports XSLT 2.0. XSLT != XPath.
Yes, 3.5 XPathNavigator supports XSLT 2.0.
http://msdn.microsoft.com/en-us/library/system.xml.xpath.xpathnavigator.aspx
"The XPathNavigator class in the System.Xml.XPath namespace is an abstract class which defines a cursor model for navigating and editing XML information items as instances of the XQuery 1.0 and XPath 2.0 Data Model."
There are some things in XSLT 2.0 that aren't supported in the built in libraries (there was discussion on the mono mailing list about this but I can't find the information anymore). But most people never run into the corner cases that aren't supported.
Another option is to check out the open source http://saxon.sourceforge.net/ which has great support for 2.0.
EDIT (AB): the above accepted answer may be confusing. There's no support at all and there are no plans in that direction for any of the XPath 2.0 or XSLT 2.0 functions in .NET.