<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/XMLDocument/object(byApplyingXSLTString:arguments:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXMLDocument(im)objectByApplyingXSLTString:arguments:error:"
  },
  "title" : "object(byApplyingXSLTString:arguments:)"
}
-->

# object(byApplyingXSLTString:arguments:)

Applies the XSLT pattern rules and templates (specified as a string) to the receiver and returns a document object containing transformed XML or HTML markup.

```
func object(byApplyingXSLTString xslt: String, arguments: [String : String]?) throws -> Any
```

## Parameters

`xslt`

A string object containing the XSLT pattern rules and templates.

`arguments`

A dictionary containing [`NSString`](/documentation/Foundation/NSString) key-value pairs that are passed as runtime parameters to the XSLT processor. Pass in `nil` if you have no parameters to pass.
  
  > Note:
  > Several XML websites discuss XSLT parameters, including O’Reilly Media’s <http://www.xml.com>.

## Return Value

Depending on intended output, the method returns an `NSXMLDocument` object *or* an [`NSData`](/documentation/Foundation/NSData) data containing transformed XML or HTML markup. If the message is supposed to create plain text or RTF, then an `NSData` object is returned, otherwise an XML document object. The method returns  `nil` if XSLT processing did not succeed.

## Discussion

> Handling Errors in Swift:
> In Swift, this method returns a nonoptional result and is marked with the `throws` keyword to indicate that it throws an error in cases of failure.
> 
> You call this method in a `try` expression and handle any errors in the `catch` clauses of a `do` statement, as described in [Error Handling](https://docs.swift.org/swift-book/LanguageGuide/ErrorHandling.html) in [The Swift Programming Language](https://docs.swift.org/swift-book/) and `About Imported Cocoa Error Parameters`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)