XSLT: Select following-sibling until reaching a specified tag

Try this: (Instead of asking for all the p’s we ask for all the p’s whose most recently preceding h1 is current.) <?xml version=”1.0″?> <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output method=”xml” indent=”yes”/> <xsl:template match=”https://stackoverflow.com/”> <content> <xsl:apply-templates/> </content> </xsl:template> <xsl:template match=”h1″> <xsl:variable name=”header-id” select=”generate-id(.)”/> <section> <sectionHeading> <xsl:apply-templates/> </sectionHeading> <sectionContent> <xsl:for-each select=”following-sibling::p[generate-id(preceding-sibling::h1[1]) = $header-id]”> <paragraph> <xsl:value-of select=”.”/> </paragraph> </xsl:for-each> … Read more

Including an XML file in an XML/XSL file

I. Here is how any XML document or fragment can be embedded in an XSLT stylesheet and used during the transformation: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” xmlns:my=”my:my”> <xsl:output omit-xml-declaration=”yes” indent=”yes”/> <xsl:strip-space elements=”*”/> <my:menu> <menu> <choice>A</choice> <choice>B</choice> <choice>C</choice> </menu> </my:menu> <xsl:template match=”https://stackoverflow.com/”> <xsl:copy-of select=”document(”)/*/my:menu/*”/> </xsl:template> </xsl:stylesheet> When this transformation is applied on any XML document (not used in … Read more

Converting XML to escaped text in XSLT

Your code works the way it does because xsl:value-of retrieves the string-value of the node set. To do what you want, I’m afraid that you’ll have to code it explicitly: <xsl:template match=”https://stackoverflow.com/”> <TestElement> <xsl:apply-templates mode=”escape”/> </TestElement> </xsl:template> <xsl:template match=”*” mode=”escape”> <!– Begin opening tag –> <xsl:text>&lt;</xsl:text> <xsl:value-of select=”name()”/> <!– Namespaces –> <xsl:for-each select=”namespace::*”> <xsl:text> xmlns</xsl:text> … Read more

How to query xml column in tsql

How about this? SELECT EventID, EventTime, AnnouncementValue = t1.EventXML.value(‘(/Event/Announcement/Value)[1]’, ‘decimal(10,2)’), AnnouncementDate = t1.EventXML.value(‘(/Event/Announcement/Date)[1]’, ‘date’) FROM dbo.T1 WHERE t1.EventXML.exist(‘/Event/Indicator/Name[text() = “GDP”]’) = 1 It will find all rows where the /Event/Indicator/Name equals GDP and then it will display the <Announcement>/<Value> and <Announcement>/<Date> for those rows. See SQLFiddle demo

How do I use PowerShell to Validate XML files against an XSD?

I want to comment that the script in current accepted answer doesn’t validate errors about incorrect orders of elements of xs:sequence. For example: test.xml <addresses xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=’test.xsd’> <address> <street>Baker street 5</street> <name>Joe Tester</name> </address> </addresses> test.xsd <xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”> <xs:element name=”addresses”> <xs:complexType> <xs:sequence> <xs:element ref=”address” minOccurs=”1″ maxOccurs=”unbounded”/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name=”address”> <xs:complexType> <xs:sequence> <xs:element ref=”name” … Read more