-
-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loop through xml elements in handlebars template #970
Comments
The I'll update https://github.com/Handlebars-Net/Handlebars.Net.Helpers to return a list which can be used in an |
@rmeshksar So for this XML: <?xml version='1.0' standalone='no'?>
<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ns=""http://www.Test.nl/XMLHeader/10"">
<soapenv:Header>
<ns:TestHeader>
<ns:HeaderVersion>10</ns:HeaderVersion>
</ns:TestHeader>
</soapenv:Header>
<soapenv:Body>
<req>
<TokenIdLijst>
<TokenId>0000083256</TokenId>
<TokenId>0000083259</TokenId>
</TokenIdLijst>
</req>
</soapenv:Body>
</soapenv:Envelope>; And this C# code: [Fact]
public void SelectNodes_InEachLoop()
{
// Arrange
var request = new
{
body = MiniTestSoapMessage
};
var expression = "{{#each (XPath.SelectNodes body \"//*[local-name()='TokenId']/text()\")}}\r\n{{this}}\r\n{{/each}}";
var action = _handlebarsContext.Compile(expression);
// Act
var result = action(request);
// Assert
result.Should().Be("0000083256\r\n0000083259\r\n");
} Returns this: I think this is what you need? |
This is exactly what I was looking for. Thanks for the quick response. For now I did something by splitting the string and loop through that but I will use this much much better approach when it is released.
|
I also would like to ask another question here: But I cannot use it with another string function like Uppercase. What do you suggest? |
I can add a method |
That would be great. Evaluate("<x><a id=\"1\"></a></x>", "//a/@id").ToString().Dump(); // <-- 1
Evaluate("<x><a id=\"1\"></a><a id=\"2\"></a></x>", "//a/@id").ToString().Dump(); // <-- 1, 2 |
Maybe also a ToString() helper is a good addition to the helpers. |
EvaluateToString has been added, see PR.
|
In the next days I will create a new NuGet for Handlebars.Net.Helpers and I'll include this in WireMock.Net |
This is amazing. Thanks |
I have a request with XML body. In the response template, I would like to loop through some of the elements of the request and add new elements to the response.
XPath.SelectNodes helpers returns a string and I cannot use {{#each method on it.
Wondering if there is any way to do it?
Maybe adding a new Handlebars helper?
The text was updated successfully, but these errors were encountered: