Jump to content

Martin Honnen

Members
  • Posts

    327
  • Joined

  • Last visited

Martin Honnen's Achievements

Member

Member (2/7)

16

Reputation

  1. With XSLT 2.0 you can process any sequence so <xsl:for-each select="1 to 5">...</xsl:for-each> processes a sequence of five integers 1,2,3,4,5. Make sure you store the input document you want to process outside of the for-each in a variable if you want to access it inside of the for-each as the context item is the currently processed integer number.
  2. Assuming you have an XSLT 2.0 processor like Saxon 9 or XmlPrime or Exselt or Altova and you want to split up a string into a sequence of strings where each string has a certain size then [ <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mf="http://example.com/mf" exclude-result-prefixes="xs mf" version="2.0"> <xsl:function name="mf:split" as="xs:string*"> <xsl:param name="input" as="xs:string"/> <xsl:param name="size" as="xs:integer"/> <xsl:for-each-group select="string-to-codepoints($input)" group-adjacent="(position() - 1) idiv $size"> <xsl:sequence select="codepoints-to-string(current-group())"/> </xsl:for-each-group> </xsl:function> <xsl:template match="/" name="main"> <xsl:value-of select="mf:split('123456789012345678901234567890123', 5)" separator=" "/> </xsl:template> </xsl:stylesheet> outputs 12345 67890 12345 67890 12345 67890 123
  3. Which XSLT processor do you use, which XSLT version? There are no arrays in XSLT 1.0 and 2.0, so your whole question about "splitting into an array" sounds odd. Unless you work with XPath 3.1 where arrays exist but then you need to tell so.
  4. I only know Saxon 9 which comes in various editions, the open source Home Edition HE should suffice for your needs to use XSLT and XPath 2.0, at least in terms of support of the specification. There are also the commercial Personal Edition PE and the Enterprise Edition EE for which one has to buy a license. I don't know of any other Java XSLT 2.0 implementation, other than that IBM Websphere package I already mentioned. Some things you want to do like getting the current date could be done with Xalan by making use of parameters or by making use of extension functions calling into Java.
  5. Yes, I think so, the current-date() function was introduced in XSLT/XPath 2.0 which is not supported by Xalan as it is an XSLT 1.0 processor.
  6. If you want to use XSLT and XPath 2.0 with Java then the built-in XSLT processor Xalan does not work as it is an XSLT 1.0 processor, you will need to switch to Saxon 9 from http://saxon.sourceforge.net/ (or if you use IBM Websphere you can check with them, I think they provide XSLT 2.0 as a package as well).
  7. Which XSLT 2.0 processor do you use? Don't you get some more detailed information like the line number in your code where the error occurs?
  8. XML started without a concept of namespaces but it got added soon. And nowadays most of XML is processed in a namespace-aware mode where names with colons are allowed but have a special meaning, see http://en.wikipedia.org/wiki/XML_namespace. So normally an XML documents looks like <html xmlns="http://www.w3.org/1999/xhtml">...</html> or <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">...</xsl:stylesheet> As for XPath and XSLT and XQuery, they all operate on XML with namespaces. If you have a namespace well-formed XML input document like <root> <prefix:name xmlns:prefix="http://example.org/">foo</prefix:name></root> then your XSLT needs to declare the namespace as well e.g. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:prefix="http://example.org/"> <xsl:template match="root"> <xsl:value-of select="prefix:name"/></xsl:template> </xsl:stylesheet> If you still have problems, post your XML sample.
  9. Your code looks fine to me. Any chance your real XML has some <output xmlns="http://example.org">...</output> ?
  10. Change <xsl:for-each select="parameters/param"> to <xsl:for-each select="parameters/param |document('file2.xml')/parameters/param">
  11. When compiling your stylesheet, your XSLT processor should tell you that the `xsl:with-param` is not allowed where you put it. For instance with <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="root"> <xsl:apply-templates select="foo"/> <xsl:with-param name="p" select="1"/></xsl:template></xsl:stylesheet> Saxon 6.5.5 tells me Error at xsl:with-param on line 7 of file:/C:/Users/Foo/Bar/sheet.xsl xsl:with-param cannot appear as a child of xsl:template
  12. It sounds a bit as if you want to define a schema for your class of XML documents and then validate XML instance documents with a validating parser against the schema.
  13. A SAX parser can do that: http://www.saxproject.org/apidoc/org/xml/sax/EntityResolver.html. XSLT does not have DTDs or entities in its data model so it is not suitable to solve your problem.
  14. Given the XML you have the "a" elements are children of the "p" elements so you would need to use <xsl:for-each select="rss/channel/item/description/p[2]"><img src="{a/@href}" style="margin:5px 5px" /></xsl:for-each>
  15. Write a template <xsl:template match="*:ExportXML"> <JobPositionPostings> <xsl:apply-templates/> </JobPositionPostings></xsl:template> and remove the element from the other template, that is change <xsl:template match="*:record"> <JobPositionPostings> <JobPositionPosting> <xsl:apply-templates select="*:field[starts-with(@name,'ContestNumber')]"/> <JobDisplayOptions> <xsl:apply-templates select="*:field[starts-with(@name,'ManagerRequisitionTitle')]"/> </JobDisplayOptions> </JobPositionPosting> </JobPositionPostings> </xsl:template> to <xsl:template match="*:record"> <JobPositionPosting> <xsl:apply-templates select="*:field[starts-with(@name,'ContestNumber')]"/> <JobDisplayOptions> <xsl:apply-templates select="*:field[starts-with(@name,'ManagerRequisitionTitle')]"/> </JobDisplayOptions> </JobPositionPosting> </xsl:template>
×
×
  • Create New...