I'm trying to add a tag like
<div itemscope>
in my xslt transformation but I get an error.(The expected token is '=')
I'm working in C# .net 4.0 xslt 1.0.
XSLT is optimized for generating XML output. HTML5 is, in general, not XML. The syntax
<div itemscope>
is clearly not XML and therefore can't be generated using xsl:attribute. This is because XML doesn't support empty-valued attributes. That's the bad news.
The good news: There are two ways of writing the same thing as <div itemscope> that are valid HTML5 and valid XML:
<div itemscope="">
<div itemscope="itemscope">
So pick your favorite and generate that!
<xsl:text disable-output-escaping="yes"><![CDATA[<div itemscope>]]></xsl:text>
Related
I have a solution that uses asp.net web api to convert data to pdf.
I am using #Raw to display the data in a html formatted manner. But the problem is that if the json string contains the html <br> it throws an error. Once I change it manually to XHTML <br/> it works fine.
Why can't #Raw handle html breaks ? Is there a better way to handle html tags?
Description
#Raw(#Model.Description)
For security reasons, Raw method is not recommended for using - it does not encode input string. The better solution, especially when you already use Web API, would be to just return the non-formatted data, and do the html formatting on the client-side, maybe using some templates library.
I need to add an attribute in with in div tag in thymleaf as follows
<div class="mp_snippet_address" itemscope itemtype="http://schema.org/LocalBusiness">
the problem is i could not define the itemscope in div tag
The standard HTML parser in Thymeleaf is a very strict XML parser. You can switch to the less-strict LEGACYHTML5 template mode (then include the nekoHTML 1.9.15+ as a dependency), which allows for 'boolean attributes', but the output may be slightly different than the input templates as I think it performs some kind of tag balancing to massage HTML5 into being well-formed XML.
Support for HTML as per the HTML spec is on the cards for Thymeleaf 3.0, but that version is still a very very very long way away.
I'm using MVC 3 and Razor as View Engine, for my understanding HTML tags are decoding by default to prevent XSS attacks or similar. (I'm also using MS XSS 4.2.1 Library)
I have a View showing some data
<div class="display-label">Code</div>
<div class="display-field">
#Html.DisplayFor(model => model.Code).
</div>
Model.Code is HTML code for some Banners, I need to display the HTML on the page DECODED.
My question: How can I decode the HTML for just model.Code living the rest ENCODED?
Thanks for your help
To display raw html use
#Html.Raw(model.Code)
Be extremely careful though
you can use to output the data as is without encoding :
#Html.Raw(model.Code)
Use is #MvcHtmlString.Create(#Model.OurVision)
i have xml file created in other asp.net project,these file include some controls and their attributes.i need to show those controls on my mvc project,
xml file format may be like below.
<div style='left:84px;top: 50px;' ><input id='Text1' type='text' value='Mr.Temp'/></div>
<div style='left:8px;top: 50px; position: fixed;' >Name</div>
<div style='left:84px;top: 650px;' ><input id='Text1' type='text' value='30'/></div>
<div style='left:8px;top: 65px; position: fixed;' >Age</div>
<div style='left:84px;top: 90px;' ><input id='Text1' type='text' value='Singapore'/></div>
<div style='left:8px;top: 90px;' >Address</div>
i need to show these controls depend on their type and location like this.
Name Mr.Temp
Age 30
Address Singapore
So,i read xml file and write ,my problem is i can create controls based on their type,but i don't know how to
assign their position correctly?Their old location can't use any more because mine is asp.net mvc project.
Give me right way,please.
regards
Indi
Have you considered using xslt? Then you can write rules around all that.
Or, if you don't want to use xslt, then consider using jQuery and write your own plugin to look through your xml and transform that to html.
edit
Well with a plug in you can check out how to write a jQuery plugin here.
Essentially what you'll be doing is giving the xml to the plugin and then the plugin will generate the html for you.
It's a bit too involved for here but you can "each()" on the div, store the first one, then the second and generate html for the pair then move to the next two.
$(xmlDoc).find("div").each(function(){
//this will get each div. now you need to create html for each and return the
//whole as a string to be rendered.
});
I'm trying to include a raw Mako template to make it appear in a textarea with Pylons.
In Pylons, I know I can include one Mako template in another like this:
<html>
<body>
Here is some HTML. Now, I want to include a template.
<%include file="${c.a_mako_template}" />
</body>
</html>
Is there a way that I can do the same thing, but have the template appear as raw markup rather than passing through Mako renderer? I'm imagining something like:
<%include file="${c.a_mako_template}" render="false" />
If that sort of thing is impossible, is the best route to write a Pylons controller that does the inclusion at a later stage?
Could I somehow wrap the file to be included in <%text> tags on the fly, perhaps using <% def>?
I've figured out a sort of workable solution. It still has one rough bit, but it works.
<%
path = '/path/to/file/'
f = open(path + c.sourcefile, 'r')
text_to_edit = f.read()
f.close()
%>
<textarea id="code">
${text_to_edit}
</textarea>
The first part is just a chunk of Python embedded in the template. It opens the file and extracts the text, thereby bypassing Mako.
The rough bit is the hardcoded path. I'll have to pass that as c.path, or something like that.