How to convert newline into with XSLT? [duplicate]

This transformation: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output omit-xml-declaration=”yes” indent=”yes”/> <xsl:template match=”t”> <p> <xsl:apply-templates/> </p> </xsl:template> <xsl:template match=”text()” name=”insertBreaks”> <xsl:param name=”pText” select=”.”/> <xsl:choose> <xsl:when test=”not(contains($pText, ‘&#xA;’))”> <xsl:copy-of select=”$pText”/> </xsl:when> <xsl:otherwise> <xsl:value-of select=”substring-before($pText, ‘&#xA;’)”/> <br /> <xsl:call-template name=”insertBreaks”> <xsl:with-param name=”pText” select= “substring-after($pText, ‘&#xA;’)”/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> when applied on this XML document: <t>Line1 Line2 Line3 </t> … Read more

Validate an XML file against local DTD file with Java

In an ideal world, you’d be able to validate using a Validator. Something like this: SchemaFactory schemaFactory = SchemaFactory .newInstance(XMLConstants.XML_DTD_NS_URI); Schema schema = schemaFactory.newSchema(new File( “xmlValidate.dtd”)); Validator validator = schema.newValidator(); validator.validate(new StreamSource(“xmlValidate.xml”)); Unfortunately, the Sun implementation (at least, as of Java 6) does not include support for creating a Schema instance from a DTD. You … Read more

How do you output the current element path in XSLT?

The currently accepted answer will return incorrect paths. For example, the element Ele2 in the OP sample XML would return the path /Doc[1]/Ele2[2]. It should be /Doc[1]/Ele2[1]. Here’s a similar XSLT 1.0 template that returns the correct paths: <xsl:template name=”genPath”> <xsl:param name=”prevPath”/> <xsl:variable name=”currPath” select=”concat(“https://stackoverflow.com/”,name(),'[‘, count(preceding-sibling::*[name() = name(current())])+1,’]’,$prevPath)”/> <xsl:for-each select=”parent::*”> <xsl:call-template name=”genPath”> <xsl:with-param name=”prevPath” select=”$currPath”/> … Read more

How can I serialize internal classes using XmlSerializer?

From Sowmy Srinivasan’s Blog – Serializing internal types using XmlSerializer: Being able to serialize internal types is one of the common requests seen by the XmlSerializer team. It is a reasonable request from people shipping libraries. They do not want to make the XmlSerializer types public just for the sake of the serializer. I recently … Read more

Android XML rounded clipped corners

2018 Update A lot has changed in the last 7 years. The best way to handle this type of layout these days is to use CardView which has built in support for rounded corners and many other newer UI features as well. Apply the cardCornerRadius property to set the corners to round. <android.support.v7.widget.CardView ……. app:cardCornerRadius=”16dp”> … Read more